what is the ordering of an AST tree?

Robert Brewer fumanchu at amor.org
Sun Feb 29 21:50:27 CET 2004

Stephen Emslie wrote:
> What I am trying to do then is essentially locate the most recent
> assignment that a variable has been given. The way I would 
> assume to do
> that would be to traverse up the tree (assuming it is in fact 
> in the order
> of the program flow) and search for the closest ASSIGN node 
> that involves
> the variable name specified.
> The trick is now that I dont know how to traverse up an AST 
> tree. And from
> what I've seen its a bit nasty. Any ideas on how to traverse 
> up an AST tree?

All you have to do now is recursively unpack the tuple that the compiler
module spent so much time and effort packing up for you. ;) If speed is
an issue, examine the source code for compiler.Transformer and rewrite
it* to skip all the tuple-creation code, and just trap the assignment

Robert Brewer
Amor Ministries
fumanchu at amor.org

* In a new module, of course! Don't hose your base install. ;)

More information about the Python-list mailing list