Keyword arguments and user-defined dictionaries

G. S. Hayes sjdevnull at yahoo.com
Thu Jun 24 14:38:44 EDT 2004


Christopher T King <squirrel at WPI.EDU> wrote in message news:<Pine.LNX.4.44.0406241012001.8058-100000 at ccc8.wpi.edu>...
> > My question is, what methods do I need to implement to make ** work on
> > a custom dictionary-like object, or is it not possible?
> 
> As far as I can tell, it's not possible.....
[SNIP]
> > If the syntax "**expression" appears in the function call, "expression" 
> > must evaluate to a (subclass of) dictionary
> 
> which seems pretty indicative that Python's shortcutting function calls
> for efficiency reasons.

Darn. 

> Your best bet is probably to call the function as func(**dict(mydict)). 
> dict() doesn't shortcut custom methods, so this should act as expected.

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

Thanks for your time.



More information about the Python-list mailing list