sqlite3 - How to create a sqlite table from a python class? -
i'd create function maketable create sqlite table python class. have class:
class foo(object): def __init__(self): self.a self.b self.c i tried defining function in way:
def maketable(obj): conn = sqlite3.connect(sqlfilename) cursor = conn.cursor() cursor.execute(sqlstring) but have create sqlstring such as:
"""create table foo (a text, b text)""" how can create sqlstring automatically given class?
alecxe not asking question, proposes use orm sqlalchemy. approach quite simple , limited. in real live have figure out, data type column should have, attributes/properties should go database , many other details. orm , sqlalchemy best 1 in opinion.
i case think you're happy simpler solution, have describe simple solution us. or better: show code wrote , did not work.
Comments
Post a Comment