Re: Factory function with keyword arguments

2007-09-23 Thread Ron Adam
Steven D'Aprano wrote: > On Sun, 23 Sep 2007 03:55:45 -0500, Ron Adam wrote: > >> Steven D'Aprano wrote: >>> I'm writing a factory function that needs to use keywords in the >>> produced function, not the factory. Here's a toy example: > > [snip] > > Thanks everyone who answered, you've given

Re: Factory function with keyword arguments

2007-09-23 Thread Ben Finney
Steven D'Aprano <[EMAIL PROTECTED]> writes: > A valuable lesson... always measure before guessing whether code > will be slow or not. And after measuring, don't guess then either :-) -- \"Science doesn’t work by vote and it doesn’t work by | `\ authority." —Richard D

Re: Factory function with keyword arguments

2007-09-23 Thread Steven D'Aprano
On Sun, 23 Sep 2007 03:55:45 -0500, Ron Adam wrote: > Steven D'Aprano wrote: >> I'm writing a factory function that needs to use keywords in the >> produced function, not the factory. Here's a toy example: [snip] Thanks everyone who answered, you've given me a lot of good ideas. I've run some t

Re: Factory function with keyword arguments

2007-09-23 Thread David
On 9/23/07, Ron Adam <[EMAIL PROTECTED]> wrote: > > > Steven D'Aprano wrote: > > I'm writing a factory function that needs to use keywords in the produced > > function, not the factory. Here's a toy example: > http://docs.python.org/whatsnew/pep-309.html -- http://mail.python.org/mailman/listinfo

Re: Factory function with keyword arguments

2007-09-23 Thread Ron Adam
Steven D'Aprano wrote: > I'm writing a factory function that needs to use keywords in the produced > function, not the factory. Here's a toy example: > I thought of doing this: > > def factory(flag): > if flag: kw = 'spam' > else: kw = 'ham' > def foo(obj, arg): > kwargs =

Re: Factory function with keyword arguments

2007-09-22 Thread George Sakkis
On Sep 22, 10:53 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > I'm writing a factory function that needs to use keywords in the produced > function, not the factory. Here's a toy example: > > def factory(flag): > def foo(obj, arg): > if flag: > # use th

Re: Factory function with keyword arguments

2007-09-22 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > def factory(flag): > if flag: kw = 'spam' > else: kw = 'ham' > def foo(obj, arg): > kwargs = dict([(kw, arg)]) > return obj.method(**kwargs) > return foo Untested: def factory(flag): def foo(obj, arg):