Hi Damjan, Thanks for your explanation, In my case lambda needs because I am trying to follow Werkzeug tutorial where session, locals etc. are separated between different files such as utils.py, application.py etc In case of separation without lamda your latest solution doesn't work.
Cheers, VP On Sep 20, 2:25 pm, Damjan <[email protected]> wrote: > On Sep 20, 8:12 pm, Damjan <[email protected]> wrote: > > > > By the way can somebody explain me this trick "()": > > > > session = scoped_session(lambda: sessionmaker > > > (bind=application.database_engine)(), local_manager.get_ident) > > > sessionmaker is a factory function, ie a function that returns a > > function. with sessionmaker(..)() you immediately call the returned > > function (with no arguments in this case). > > > I do wonder why you need "lambda: sessionmaker(..)()" as an argument > > though? It seems to me it's the same as if you used just "sessionmaker > > (..)" as the first argument. > > and seems to work here: > > import sqlalchemy > import werkzeug > from sqlalchemy.orm import scoped_session, sessionmaker > > sqlite_db = sqlalchemy.create_engine('sqlite:////tmp/foo.db') > local_manager = werkzeug.LocalManager() > session = scoped_session(sessionmaker(bind=sqlite_db), > local_manager.get_ident) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pocoo-libs" 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/pocoo-libs?hl=en -~----------~----~----~----~------~----~------~--~---
