I have an error i cant figure out (likely a beginners error):
#--------------------------------------------------------
Base = declarative_base()
class tablemeta(DeclarativeMeta):
def __new__(mcls, name):
return DeclarativeMeta.__new__(mcls, name, (Base,), {})
def _init__(cls, name):
temp = dict()
temp["__tablename__"] = "_" + name
temp["id"] = Column(Integer, primary_key = True)
temp["text"] = Column(String(120))
DeclarativeMeta.__init__(cls, name, (Base,), temp)
if __name__ == "__main__":
engine = create_engine('sqlite:///:memory:', echo=True)
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
table1 = tablemeta("table1") #=> ERROR
row1 = table1(text = "detextenzo")
row2 = table1(text = "detextenzoennogeenbeetje")
session.commit()
list = session.query(table1).all()
for l in list:
print str(l)
print "done"
#--------------------------------------------------------
the error is:
#--------------------------------------------------------
Traceback (most recent call last):
File "D:\Documents\Code\NetBeans\test\temp\src\temp.py", line 33, in
<module>
table1 = tablemeta("table1")
TypeError: __init__() takes exactly 4 arguments (2 given)
#--------------------------------------------------------
I do not understand what __init__ i am miscalling: I call
tablemeta.__init__ with 2 (1 implicit) as defined and
DeclarativeMeta.__init__ with 4 as defined?
please help ...
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.