class my_types:
def __init__(self):
self.my_types = [email_type, negotive_type, positive_type]
def check_types(self, check_type):
for my_type in self.my_types:
obj = my_type()
if obj.check_type(check_type):
return obj.type_name()
return "Unknown type"
class email_type(my_types):
def check_type(self, check_type):
if "@" in check_type:
return True
return False
def type_name(self):
return "email_type"
class negotive_type(my_types):
def check_type(self, check_type):
if "no" in check_type:
return True
return False
def type_name(self):
return "negotive_type"
class positive_type(my_types):
def check_type(self, check_type):
if "yes" in check_type:
return True
return False
def type_name(self):
return "positive_type"
check_types = ["test@", "yes", "no"]
obj = my_types()
for check_type in check_types:
print("{} - {}".format(check_type, obj.check_types(check_type)))
test@ - email_type
yes - positive_type
no - negotive_type
if self.radio_button_3.isChecked():
self.bth_vis.clicked.connect(self.function2)
else:
self.bth_vis.clicked.connect(self.function1)
self.bth_vis.clicked.connect(self.make_choice)
.
.
.
def make_choice(sefl):
if self.radio_button_3.isChecked():
self.func_1()
else:
self.func_2()
(?<!\d)(\d{1,2}|100)(?!\d)
import json
str = '{"code":"000000","message"...}'
data = json.loads(str)
print(data["data"][0]["adv"]["maxSingleTransAmount"])
Мой проект использует же только вирт окружение? если в нем нет модуля ide не ищет его где то еще?
поэтому скачивать для каждого проекта одни и те же модули не разумно
radiobutton.setChecked(False)
rb_1.func = "func_1"
rb_1.toggled.connect(self.on_rb_select)
rb = self.sender()
if rb.isChecked():
self.rb_selected = rb.func
def on_btn_click(self):
if self.rb_selected == "func_1":
self.func_1()
if self.rb_selected == "func_2":
self.func_2()
from PyQt5.QtWidgets import *
import sys
class main_window(QWidget):
def __init__(self):
QWidget.__init__(self)
self.rb_selected = 1
layout = QVBoxLayout()
self.setLayout(layout)
self.label = QLabel()
layout.addWidget(self.label)
gb_layout = QHBoxLayout()
gb_widget = QWidget()
gb_widget.setLayout(gb_layout)
gb = QButtonGroup(gb_widget)
rb_1 = QRadioButton()
rb_1.setChecked(True)
rb_1.func = "func_1"
rb_1.toggled.connect(self.on_rb_select)
gb.addButton(rb_1)
gb_layout.addWidget(rb_1)
rb_2 = QRadioButton()
rb_2.setChecked(False)
rb_2.func = "func_2"
rb_2.toggled.connect(self.on_rb_select)
gb.addButton(rb_2)
gb_layout.addWidget(rb_2)
layout.addWidget(gb_widget)
self.btn = QPushButton("Press me")
self.btn.clicked.connect(self.on_btn_click)
layout.addWidget(self.btn)
def on_btn_click(self):
if self.rb_selected == "func_1":
self.func_1()
if self.rb_selected == "func_2":
self.func_2()
def on_rb_select(self):
rb = self.sender()
if rb.isChecked():
self.rb_selected = rb.func
def func_1(self):
self.label.setText("func_1")
def func_2(self):
self.label.setText("func_2")
if __name__ == "__main__":
app = QApplication(sys.argv)
screen = main_window()
screen.show()
sys.exit(app.exec_())
from PyQt5.QtWidgets import *
import sys
class Window(QWidget):
def __init__(self):
QWidget.__init__(self)
layout = QVBoxLayout()
self.setLayout(layout)
self.label = QLabel("Сумма = 0")
layout.addWidget(self.label)
self.sum = 0
self.gb_list = {}
for i in range(1, 10):
gb_layout = QHBoxLayout()
gb_widget = QWidget()
gb_widget.setLayout(gb_layout)
gb = QButtonGroup(gb_widget)
for j in range(1, 10):
radiobutton = QRadioButton()
radiobutton.setChecked(False)
radiobutton.number = "{}".format(i)
radiobutton.value = "{}".format(j)
radiobutton.toggled.connect(self.onClicked)
gb.addButton(radiobutton)
gb_layout.addWidget(radiobutton)
layout.addWidget(gb_widget)
def onClicked(self):
radioButton = self.sender()
if radioButton.isChecked():
self.gb_list[radioButton.number] = int(radioButton.value)
self.label.setText("Сумма = {}".format(sum(self.gb_list.values())))
app = QApplication(sys.argv)
screen = Window()
screen.show()
sys.exit(app.exec_())
c = set(text1.split()).difference(set(text2.split()))
for i, w in enumerate(text1.split()):
if w in c:
print("{} -> {}".format(w, text2.split()[i]))
else:
print(w)
Сергей
сегодня
получил
двойку -> отлично
на
уроке.
Дома
ждет
его
наказание. -> подарок.
def __eq__(self, other):
from datetime import datetime, timedelta
class dt:
def __init__(self, time=None):
self.dt = datetime.now()
if time:
self.dt = datetime.strptime(str(time), '%Y%m%d%H%M')
def plus_min(self, min=0):
self.dt += timedelta(minutes=5)
return self
def minus_min(self, min=0):
self.dt -= timedelta(minutes=5)
return self
def get_time(self):
return self.dt
def eq(self, time):
return self.dt == time
def set_date(self, dt=datetime.now()):
self.dt = dt
return self
if __name__ == '__main__':
a = dt('202204061200')
print(a.plus_min(5).get_time())
print(a.minus_min(5).get_time())
print(a.eq('202204061300'))
print(a.set_date().eq('202204061300'))
class dt:
def __init__(self, time=None):
self.dt = datetime.now()
if time:
self.dt = datetime.strptime(str(time), '%Y%m%d%H%M')
def get_dt(self):
return self.dt
class dt_operation:
def eq(self, dt1, dt2=datetime.now()):
return dt1 == dt2
if __name__ == '__main__':
d1 = dt('202204061300')
d2 = dt('202204061300')
op = dt_operation()
print(op.eq(d1.get_dt(), d2.get_dt()))