#
sqlite_connection = sqlite3.connect('sqlite_python.db')
cursor = sqlite_connection.cursor()
sqlite_select_query = """SELECT * from sqlitedb_developers"""
cursor.execute(sqlite_select_query)
records = cursor.fetchall()
for row in records:
print("ID:", row[0])
print("Имя:", row[1])
print("Почта:", row[2])
print("Добавлен:", row[3])
print("Зарплата:", row[4], end="\n\n")
sqlite_connection = sqlite3.connect('sqlite_python.db')
sqlite_connection.row_factory = sqlite3.Row
cursor = sqlite_connection.cursor()
sqlite_select_query = """SELECT * from sqlitedb_developers"""
cursor.execute(sqlite_select_query)
records = cursor.fetchall()
records = [dict(row) for row in records]
print(records)
row
всегда равна длине ROW_HEADS
, это лучше проверять, иначе могут быть ошибки и сбои.ROW_HEADS = ["ID:", "Имя:", "Почта:", "Добавлен:", "Зарплата:"]
def make_string(row):
return '\n'.join([f'{key} {value}' for key, value in zip(ROW_HEADS, row)])
if __name__ == '__main__':
row = (1, 2, 3, 4, 5)
print(make_string(row))