> -----Original Message-----
> From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com]
> On Behalf Of farcat
> Sent: 16 March 2011 21:01
> To: sqlalchemy
> Subject: [sqlalchemy] trouble with metaclass
> 
> 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 ...
> 

I'm not sure if it's the cause of your problem, but you have a typo in
tablemeta - your __init__ only has 1 underscore at the beginning...

Hope that helps,

Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to