Ast tree and python code

Yermat loic at yermat.net1.nerim.net
Thu Mar 4 12:08:45 EST 2004


Robert Brewer a écrit :
> Yermat wrote:
> 
>>Does someone know how I can reverse an AST tree back into python code 
>>with few modification ?
>>What I want to do is to complete trees before writing them 
>>back but in a 
>>way not to far from the original code ? Especially, indentation, line 
>>return, etc.
>>
>>Of course, I could program it myself but if someone already done it...
> 
> 
> I don't know of a full implementation (someone else might?) but I made a
> start of it a week ago:
> 
> http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=mailman.219.1077
> 918544.8594.python-list%40python.org
> 
> Deriver.process() (inherited from Processor.process()) produces Python
> statements from an AST node; it's only simple expressions at the
> moment--no assignment, for example. Feel free to build on it.
> 
> 
> Robert Brewer
> MIS
> Amor Ministries
> fumanchu at amor.org
> 

Thank,
That's what I was thinking, I need to do it myself ;-)
I found today that in fact I can work with 2 tree, the parser one and 
the AST one. But even with the former one, the ouput is not really like 
the input. What a shame ! ;-)

I'm going to use the parser tree even if adding new line of python in it 
is a big mess...

http://groups.google.fr/groups?q=ast2string&hl=fr&lr=&ie=UTF-8&oe=UTF-8&selm=Pine.LNX.4.10.10012281200430.23773-100000%40kev.ioc.ee&rnum=1

Thank




More information about the Python-list mailing list