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


Groups > comp.lang.python > #66707 > unrolled thread

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

Started byDan Goodman <dg.gmane@thesamovar.net>
First post2014-02-19 17:40 +0000
Last post2014-02-19 17:40 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

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

FromDan Goodman <dg.gmane@thesamovar.net>
Date2014-02-19 17:40 +0000
SubjectRe: Turning an AST node / subnodes into something human-readable
Message-ID<mailman.7158.1392831639.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web