Page 1 of 1

Python Datacklasse und SQLite3 -Adapter

Posted: 24 Jul 2025, 21:15
by Anonymous
Wie ist die sauberste Methode, um Daten zu bestimmen, die in Instanzen einer DataClass gespeichert sind, die in einer Liste zu SQLite mit SQLite3 's Executemany ?

Code: Select all

@dataclass
class Person:
name: str
age: int

a = Person("Alice", 21)
b = Person("Bob", 22)
c = Person("Charlie", 23)

people = [a, b, c]

# ...

cursor.executemany(f"INSERT INTO {table} ({headers}) ({placeholders})", people) #