Partially evaluated functions
Nick Perkins
nperkins7 at home.com
Wed Jun 20 23:51:34 EDT 2001
Rainer Deyke:
> > >>> def f(self, **kwargs):
> > ... print self, kwargs
> > ...
> > >>> f(f, self=5)
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in ?
> > TypeError: keyword parameter redefined: self
Carsten Geckeler:
> Probably you mean
> curry(f, self=5)
> and not
> f(f, self=5)
>
> But you are right that you get a TypeError due to the __init__ function in
> the class.
Of course you get an error when you try to pass a keyword argument to a
function that does not take any keyword arguments.
( and why are you trying to pass 'self'?)
What does work, for the cookbook version, and Alex's functional version, is
any of the following:
def print_thing( thing='boat' )
print thing
print_plane = curry( print_thing, thing='plane' )
print_plane()
..now calling print_plane() will simply print 'plane'
or, the same thing without the keywords:
def print_thing( thing ):
print thing
print_plane = curry( print_thing, 'plane' )
print_plane()
or.. you can even do this:
def print_thing( thing='boat' ):
print thing
print_plane = curry( print_thing, 'plane' )
print_plane()
..with a positional arg being 'promoted' to a keyword arg.
More information about the Python-list
mailing list