Accessing Python parse trees

Kent Johnson kent37 at tds.net
Sat Mar 5 14:52:38 CET 2005


Manlio Perillo wrote:
> Anyway, here is an example of what I would like to do:
> 
> #begin
> def foo(**kwargs): print kwargs
> 
> foo(a = 1, b = 2, c = 3)
> #end
> 
> 
> In the current implementation kwargs is a dict, but I need to have the
> keyword argument sorted.
> Unfortunately subclassing fron dict and installing the class in the
> __builtin__ module (with the name 'dict') does not work, CPython uses
> only builtin types.
> 
> With the compiler module I can obtain the keyword arguments in the
> order the were specified.
> The problem is how to do this for every call to foo!

Why not just pass the kind of argument you want? What is it you really need to do?

def foo(kwds): print kwds

foo(MyDict(a = 1, b = 2, c = 3))

Kent



More information about the Python-list mailing list