Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66707

Re: Turning an AST node / subnodes into something human-readable

From Dan Goodman <dg.gmane@thesamovar.net>
Subject Re: Turning an AST node / subnodes into something human-readable
Date 2014-02-19 17:40 +0000
References <CAPTjJmp=HFJkO3DCdO47XqKMj66U_EhdyyoL-xJKBLHfCaFDMQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.7158.1392831639.18130.python-list@python.org> (permalink)

Show all headers | View raw


Chris Angelico <rosuav <at> gmail.com> writes:
> I'm working with the ast module to do some analysis on Python
> codebases, and once I've found what I'm looking for, I want to print
> something out. The file name I'm hanging onto externally, so that
> works; and the nodes all have a lineno. So far so good. But how do I
> "reconstitute" a subtree into something fit for human consumption?

I did something like this, feel free to use my code:

https://github.com/brian-team/brian2/blob/master/brian2/parsing/rendering.py

At the moment, it only works for series of mathematical statements (no
control conditions, loops, array notation, etc.), but it would be pretty
easy to add those. It also puts too many parentheses in outputted
expressions, e.g. 1+2+3 would come back as (1+2)+3, etc.

Dan

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Turning an AST node / subnodes into something human-readable Dan Goodman <dg.gmane@thesamovar.net> - 2014-02-19 17:40 +0000

csiph-web