python 2.5 and ast

Andrea Crotti andrea.crotti.0 at gmail.com
Fri Dec 2 11:54:34 EST 2011


On 12/02/2011 03:18 PM, DevPlayer wrote:
> There was another topic in these forums recently about "un-importing"
> modules (and how you can not do that reliably without restarting
> python). There was various ways mentioned of keeping track of what was
> imported. And there was mentioned reasonable ways of finding all
> possible imports on a computer.
>
> By "unused imports" I assume you mean "all unused imports in the
> application's source code" as opposed to meaning "all unused modules/
> packages/libraries on that computer."
>
> Personally I'd love to see more tutorials on the AST module; An AST
> for Dummies. Pretty much the tutorials talk about parsing an
> expression like "1+2=3". But I'd like to see how blocks are compiled/
> managed by the indent/dedent tokens and how the complete algorithm for
> finding qouted strings is implimented (using really simple
> explanations).
>
> Some google buzzwords to help with your search for your question:  sys
> import cache, import hook, pydoc walkpackages().
>
> And I just found this little tool; never knew about it: C:\PythonXX
> \Tools\Scripts\pydocui.pyw
>

Yes I meant unused imports in each of the modules actually...
The problem for me is to actually understand what are all the possible
AST node that can involve the use of an actual import, and I didn't
find anything helpful aboupt that.

The ASDL definition says everything in theory but without some examples
is a bit hard.

I got something nice however:
http://stackoverflow.com/questions/8340567/python-ast-to-dot-graph/8342383#8342383

But on windows and Python 2.5 nothing is working :/, even if I blandly 
copied the
ast.py from the python 2.7 code file..

   File "h:\long\path\devsonly\ast.py", line 166, in iter_fields
     for field in node._fields:
TypeError: 'NoneType' object is not iterable



More information about the Python-list mailing list