Yes, I think also lambda can be good one.

Though lambda reduces an effort to type a predefined function, 
functools.partial is a bit familiar to me.


Best regards,
Tate
-----Original Message-----
From: "Jackson, Cameron" <cameron.jack...@thalesgroup.com.au>
Sender: sqlalchemy@googlegroups.com
Date: Fri, 2 Dec 2011 12:44:26 
To: sqlalchemy@googlegroups.com<sqlalchemy@googlegroups.com>
Reply-To: sqlalchemy@googlegroups.com
Subject: RE: [sqlalchemy] Passing additional arguments to event listeners ?

Not sure if this helps or not, but how about using a lambda that that calls 
your function with the arguments you want? This is the solution I've been using 
for passing arguments to wxPython event handlers. This tutorial might help: 
http://wiki.wxpython.org/Passing%20Arguments%20to%20Callbacks 

-----Original Message-----
From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On 
Behalf Of Tate Kim
Sent: Friday, 2 December 2011 12:33 PM
To: sqlalchemy@googlegroups.com
Subject: Re: [sqlalchemy] Passing additional arguments to event listeners ?

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 <mike...@zzzcomputing.com>
Sender: sqlalchemy@googlegroups.com
Date: Thu, 1 Dec 2011 19:52:15 
To: <sqlalchemy@googlegroups.com>
Reply-To: sqlalchemy@googlegroups.com
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 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.

-- 
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.



-------------------------------------------------------------------------
DISCLAIMER: This e-mail transmission and any documents, files and 
previous e-mail messages attached to it are private and confidential.  
They may contain proprietary or copyright material or information that 
is subject to legal professional privilege.  They are for the use of 
the intended recipient only.  Any unauthorised viewing, use, disclosure, 
copying, alteration, storage or distribution of, or reliance on, this 
message is strictly prohibited.  No part may be reproduced, adapted or 
transmitted without the written permission of the owner.  If you have 
received this transmission in error, or are not an authorised recipient, 
please immediately notify the sender by return email, delete this 
message and all copies from your e-mail system, and destroy any printed 
copies.  Receipt by anyone other than the intended recipient should not 
be deemed a waiver of any privilege or protection.  Thales Australia 
does not warrant or represent that this e-mail or any documents, files 
and previous e-mail messages attached are error or virus free.  

-------------------------------------------------------------------------

-- 
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.

-- 
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