Accessing Python parse trees

Manlio Perillo NOmanlio_perilloSPAM at libero.it
Sat Mar 5 08:07:33 EST 2005


On 3 Mar 2005 11:15:28 -0800, "Lonnie Princehouse"
<finite.automaton at gmail.com> wrote:

>No.  I don't think it's possible to read the parse tree used by the
>interpreter, especially as it is being created. Here are a couple of
>kludgy ideas that might come close, though:

Is this a 'limitation' of the current version or it is impossible for
the architecture of CPython?
What about pypy?

>
>On a side note, check out the compiler module.  You might find it to be
>friendlier and more useful than parser.

Thanks for the hint. It is what I want.
Unfortunately is seem to be not well documented.


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!




Thanks and regards   Manlio Perillo



More information about the Python-list mailing list