How about functools.partial ? As far as I know, functools.partial will simply do this.
Usually, I import this when I need to make an argument-less function equip extra arguments. Best regards, Tate -----Original Message----- From: Michael Bayer <[email protected]> Sender: [email protected] Date: Thu, 1 Dec 2011 19:52:15 To: <[email protected]> Reply-To: [email protected] Subject: Re: [sqlalchemy] Passing additional arguments to event listeners ? On Dec 1, 2011, at 7:24 PM, Łukasz Czuja wrote: > Hi, > > I do not see anywhere in the docs a way to pass custom attributes to > event listeners: > > event.listen(cls, 'before_insert', before_insert_listener, arg1, arg2, > kwarg1 = 'value', kwarg2 = 'value2') > > so that the before_insert_listener can have mixed signature: > > def before_insert_listener(mapper, connection, target, arg1, *args, > **kwargs): > > the only other solution would be to store extra processing information > on the 'target' itself. > > Should be reasonable if there is not another way to pass around > arguments. Should I open a ticket then? this kind of pollutes the API with kwargs that might be needed for the listen() function itself someday, these are external use cases that are easily handled in Python: def before_insert_listener(arg1, arg2, k1='value', k2='value'): def before_insert(mapper, conn, target): ... body return before_insert event.listen(cls, 'before_insert', before_insert_listener(arg1, arg2, k1='x', k2='y')) -- 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. -- 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.
