reifying indent and dedent into braces

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Tue Oct 13 03:45:24 EDT 2009


On Tue, 13 Oct 2009 12:35:13 +0530, Rustom Mody wrote:

> 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]


Have you looked at the tokenize module?

http://docs.python.org/library/tokenize.html




-- 
Steven



More information about the Python-list mailing list