reifying indent and dedent into braces

Rustom Mody rustompmody at gmail.com
Tue Oct 13 09:05:13 CEST 2009


At http://www.secnetix.de/olli/Python/block_indentation.hawk
I find that the python code

>>> if foo:
...     if bar:
...         x = 42
... else:
...   print foo
...

has its indentation structure made explicit as

<if> <foo> <:>                    [0]
<INDENT> <if> <bar> <:>           [0, 4]
<INDENT> <x> <=> <42>             [0, 4, 8]
<DEDENT> <DEDENT> <else> <:>      [0]
<INDENT> <print> <foo>            [0, 2]
<DEDENT>                          [0]

Is there any api in python for going from 1st to 2nd and back?

Context: I am trying to generate some python code and its
indentation=structure is giving me a headache!



More information about the Python-list mailing list