def file_write(key, val):
try:
data = json.load(open(storage_path))
except:
data = {}
if key in data:
data[key].append(val)
else:
data[key] = [val]
with open(storage_path, "w") as f:
json.dump(data, f, indent=2, ensure_ascii=False)
def file_read(key):
with open(storage_path, "r"):
data = json.load(open(storage_path))
print(data.get(key, 'Пусто'))
if a or f < 0
if (bool(a) == True) or (bool(f < 0) == True)
import pandas as pd
data = [('18835', [{'ID': '2903', 'OWNER_ID': '18835', 'OWNER_TYPE': 'D', 'PRODUCT_ID': 3839, 'PRODUCT_NAME': 'Установка ПП 1С', 'ORIGINAL_PRODUCT_NAME': 'Установка ПП 1С', 'PRODUCT_DESCRIPTION': 'Установка ПП 1С', 'PRICE': 1300, 'PRICE_EXCLUSIVE': 1300, 'PRICE_NETTO': 1300, 'PRICE_BRUTTO': 1300, 'PRICE_ACCOUNT': '1300.00', 'QUANTITY': 1, 'DISCOUNT_TYPE_ID': 2, 'DISCOUNT_RATE': 0, 'DISCOUNT_SUM': 0, 'TAX_RATE': 0, 'TAX_INCLUDED': 'N', 'CUSTOMIZED': 'Y', 'MEASURE_CODE': 356, 'MEASURE_NAME': 'ч', 'SORT': 10}]), ('5199', []), ('23291', [{'ID': '7407', 'OWNER_ID': '23291', 'OWNER_TYPE': 'D', 'PRODUCT_ID': 6483, 'PRODUCT_NAME': 'Установка и обновление ПП', 'ORIGINAL_PRODUCT_NAME': 'Установка и обновление ПП', 'PRODUCT_DESCRIPTION': 'Установка и обновление ПП', 'PRICE': 1300, 'PRICE_EXCLUSIVE': 1300, 'PRICE_NETTO': 1300, 'PRICE_BRUTTO': 1300, 'PRICE_ACCOUNT': '1300.00', 'QUANTITY': 0.5, 'DISCOUNT_TYPE_ID': 2, 'DISCOUNT_RATE': 0, 'DISCOUNT_SUM': 0, 'TAX_RATE': 0, 'TAX_INCLUDED': 'N', 'CUSTOMIZED': 'Y', 'MEASURE_CODE': 356, 'MEASURE_NAME': 'ч', 'SORT': 10}]), ('609', [])]
# формируем список словарей со значениями по колонкам
df_data = [row[1][0] for row in data if row[1]]
prod = pd.DataFrame(df_data)
with pd.ExcelWriter('B24.xlsx',
mode='w') as writer:
prod.to_excel(writer, sheet_name='Товары')
в параметрах
columns: list[str] = ['*']
и саму строку
columns = ', '.join(columns)
where {column}={value}
# находим строку и позицию в строке
row, row_pos = divmod(pos, n)
# вычисляем новую позицию в строке и снова собираем полный номер
new_pos = row*n + (row_pos + 1)%n
new_pos = (pos - n)%total
el = {n['key_id'] for n in answer}
mylist = ['key_id']
el = {n[mylist[0]] for n in answer}
def __init__(self):
....
self.speed = SPEED
def update(self):
self.rect.x += self.speed
if self.rect.left < 0 or self.rect.right > WIDTH:
self.speed = -self.speed
def mouse_position_print (self, event):
def __init__(self):
self.window = Tk()
self.window.title("paint")
self.window.geometry("1280x720+300+150")
states = {"kb":None}
def ... клавиатура1
keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True)
button1 = telebot.types.KeyboardButton(f'Да')
button2 = telebot.types.KeyboardButton(f'Нет')
keyboard.row(button1, button2)
states["kb"] = "kb1"
bot.send_message(message.chat.id, message, reply_markup=keyboard)
def ... клавиатура2
keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True)
button1 = telebot.types.KeyboardButton(f'Да')
button2 = telebot.types.KeyboardButton(f'Нет')
keyboard.row(button1, button2)
states["kb"] = "kb2"
bot.send_message(message.chat.id, message, reply_markup=keyboard)
@bot.message_handler(content_types=['text'])
def echo_text(message):
if states["kb"] == "kb1":
if message.text == 'Да':
elif states["kb"] == "kb2":
if message.text == 'Да':
class DataBase():
def __init__(self, database_name):
self.conn = sqlite3.connect(database_name)
self.cursor = self.conn.cursor()
def commit(self):
self.conn.commit()
def close(self):
self.conn.close()
# создаем объект класса
db = DataBase('my_db.db')
cursor = db.cursor
# и в любой функции можем использовать
cursor.execute ...
db.commit()