class TestClass:
def __init__(self, number: (int, str)):
self._number = number
@property
def number(self):
if isinstance(self._number, int):
return self.__int_number()
elif isinstance(self._number, str):
return self.__str_number()
else:
return self._number
@number.setter
def number(self, value):
self._number = value
def __int_number(self):
return self._number * 100
def __str_number(self):
return f'Hello world - {self._number}'
value_int = 150
testInstance = TestClass(value_int)
print(testInstance.number)
value_str = '0MG'
testInstance.number = value_str
print(testInstance.number)
value_another_type = ['one', 'two']
testInstance.number = value_another_type
print(testInstance.number)
delta2_days = 1 # delta2.days
DELTA_DAYS = 14
FILE = r'C:\\m\\notice.ini'
REPLACE_ONE = '2-0\n'
REPLACE_TWO = '2-1\n'
def read_file(filename: str):
with open(filename, 'r') as f:
return f.read()
def write_file(filename: str, data):
with open(filename, 'w') as f:
f.write(data)
print(f'Дата {"меньше" if delta2_days <= DELTA_DAYS else "больше "} 14 дней')
# app_log.info(f'Дата {"больше" if some > DELTA_DAYS else "меньше"} 14 дней')
old_data = read_file(FILE)
new_data = old_data.replace(REPLACE_ONE, REPLACE_TWO) if delta2_days <= DELTA_DAYS else old_data.replace(REPLACE_TWO, REPLACE_ONE)
write_file(FILE, new_data)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
import static org.apache.log4j.Level.DEBUG
// define logger
def _logger = Logger.getLogger("LOGGER")
_logger.setLevel(DEBUG)
// issue
String subIssueKey = "TASKIT-249"
IssueManager issueManager = ComponentAccessor.getIssueManager()
Issue issue = issueManager.getIssueObject(subIssueKey)
_logger.debug("KEY: " + issue.getKey().toString())
if (issue.getParentObject() == null) {
_logger.debug("Issue: " + subIssueKey + " IS NOT subTask!")
throw new NullPointerException()
} else {
issue = issue.getParentObject()
_logger.debug("KEY: " + issue.getKey().toString())
}
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
String myCustomFieldCode = "customfield_10100"
CustomField myCustomField = customFieldManager.getCustomFieldObject(myCustomFieldCode)
if (myCustomField != null) {
String myCustomFieldValue = issue.getCustomFieldValue(myCustomField)
_logger.debug("Value: " + myCustomFieldValue)
} else {
_logger.debug("Field: " + myCustomFieldCode + " NOT FOUND!")
}
C:\Users\ashab\PycharmProjects\pdfhelper\venv\Scripts\python.exe
# до активации venv
C:\Users\ashab>python -V
Python 3.7.9
C:\Users\ashab>C:\Users\ashab\PycharmProjects\pdfhelper\venv\Scripts\activate
# после активации venv
(venv) C:\Users\ashab>python -V
Python 3.9.6
python "D:\PyProjects\Test\Literal2.py"
pip install payok
from payok import payok_api
balance = payok_api.getBalance(
123,
'API_KEY'
)
print(balance)
import os
import re
import pytest
def get_tsc_files(filepath: str):
return [
open(os.path.join(filepath, file)).read().strip('\n')
for file in os.listdir(filepath)
if os.path.isfile(os.path.join(filepath, file) and file.endswith('.tsv'))
]
def get_regex_emails():
return re.compile(r'([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+')
path = 'C:\Работа'
@pytest.mark.parametrize('regex, checked_file', [(get_regex_emails(), file) for file in get_tsc_files(path)])
def test_match(regex, checked_file):
assert bool(re.search(regex, checked_file)) is True
from collections import Counter
d = [
{
"type": "STARK COUNTRY LINE INTERACTIVE 600",
"power": 360,
"execution": "floor",
"dimensions": "359х97х147",
"battery output signal": "synthesized sine",
"price": 9940
},
{
"type": "STARK COUNTRY LINE INTERACTIVE 1000 LI",
"power": 600,
"execution": "floor",
"dimensions": "395х145х220",
"battery output signal": "pure sine",
"price": 19374
},
{
"type": "STARK COUNTRY ONLINE 1000 ONLINE",
"power": 900,
"execution": "floor",
"dimensions": "397х145х220",
"battery output signal": "pure sine",
"price": 28639,
"discount": 'yes',
},
{
"type": "STARK COUNTRY ONLINE 1000 ONLINE RT",
"power": 900,
"execution": "floor",
"dimensions": "438х410х88",
"battery output signal": "pure sine",
"price": 29313
},
{
"type": "STARK COUNTRY ONLINE 1000 ONLINE",
"power": 800,
"execution": "floor",
"dimensions": "397х145х220",
"battery output signal": "pure sine",
"price": 23333
}
]
items = [item['type'] for item in d]
item, item_count = Counter(items).most_common()[0]
print(f'Most common item - {item}, duplicate - {item_count} times')
from tkinter import *
from tkinter import ttk
from tkinter.messagebox import showerror, showinfo
root = Tk()
root.geometry("250x200")
def clear():
entry_username.delete(0, END)
entry_password.delete(0, END)
def open_info():
showinfo(title="Info", message="Connected")
def open_error():
showerror(title="Error", message="Incorrect input")
def connect_to_db():
accepted_user = 'admin'
accepted_password = 'admin'
try:
print('Connect to DB')
username = entry_username.get()
password = entry_password.get()
if accepted_user == username and password == accepted_password:
open_info()
else:
open_error()
except Exception:
open_error()
finally:
clear()
label_username = ttk.Label(text = "USERNAME")
label_username.pack(anchor=NW, padx=6, pady=6)
entry_username = ttk.Entry()
entry_username.pack(anchor=NW, padx=6, pady=6)
label_password = ttk.Label(text = "PASSWORD")
label_password.pack(anchor=NW, padx=6, pady=6)
entry_password = ttk.Entry()
entry_password.pack(anchor=NW, padx=6, pady=6)
display_button = ttk.Button(text="Connect", command=connect_to_db)
display_button.pack(side=LEFT, anchor=N, padx=6, pady=6)
clear_button = ttk.Button(text="Clear", command=clear)
clear_button.pack(side=LEFT, anchor=N, padx=6, pady=6)
root.mainloop()
>>> class Duck:
... def __init__(self, color):
... self.color = color
... def get_color(self):
... return self.color
...
>>>
>>>
>>> d = Duck('orange')
>>> d
<__main__.Duck object at 0x000001F569CDEA08>
>>> dir(d)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'color', 'get_color']
>>> callable(d.color)
False
>>> callable(d.get_color)
True