Keyword arguments and user-defined dictionaries
Greg Chapman
glc at well.com
Fri Jun 25 13:07:06 EDT 2004
On 24 Jun 2004 11:38:44 -0700, sjdevnull at yahoo.com (G. S. Hayes) wrote:
>Yeah, I have a .explode() method that tells the dictionary to
>de-Lazify everything; that's basically what (**dict)(mydict) would do,
>except passing as dict(mydict) would de-Lazify every function call and
>.explode() just once (though .explode would keep the exploded values
>in memory and dict(mydict) would toss them after the function
>returned).
You could do something like:
def CallWithLazy(func, lazydict):
if isinstance(func, types.MethodType):
firstarg = 1 # don't want to try to de-Lazify self arg
else:
firstarg = 0
code = func.func_code
for name in code.co_varnames[firstarg:code.co_argcount]:
lazydict[name] #or whatever is necessary to de-lazify
return func(**lazydict)
---
Greg Chapman
More information about the Python-list
mailing list