Accessing Python parse trees

Manlio Perillo NOmanlio_perilloSPAM at libero.it
Sat Mar 5 22:38:43 CET 2005


On Sat, 05 Mar 2005 08:52:38 -0500, Kent Johnson <kent37 at tds.net>
wrote:

>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

I don't understand your code.
Here an example using OrderedDict from twisted:

>>> import twisted.python.util as util

>>> foo(util.OrderedDict(a = 1, b = 2, c = 3))
{'a': 1, 'c': 3, 'b': 2}


Simply I can't use a dict.

I have to do, as an example example:
foo('a', 1, 'b', 2, 'c', 3)

or

foo(['a', 'b', 'c'], [1, 2, 3])


Thanks and regards   Manlio Perillo





More information about the Python-list mailing list