Python 2.0 parser module bug(?) and a Q
Pearu Peterson
pearu at ioc.ee
Wed Dec 27 15:27:46 EST 2000
Hi,
I have found that parser module may have a bug in its functions tuple2ast
or suite.
This is illustrated in the following python session:
>>> import parser
>>> parser.tuple2ast((parser.suite('import sys,math')).totuple())
Traceback (most recent call last):
File "<stdin>", line 1, in ?
parser.ParserError: Expected node type 280, got 279.
>>> parser.tuple2ast((parser.suite('import sys\nimport math')).totuple())
<ast object at 0x810e978>
I am using Python 2.0.
And my question is (not really related to above):
Is there inverse function for parser.suite?
For example, if I create an ast object
ast = parser.suite('x=5\ny=x+2')
then I'll transform it to tuple:
t = ast.totuple()
so that I can analyze it, create a new ast-tuple `t2' from it, may be a
bit changed, but then using
ast2 = parser.tuple2ast(t2)
I get another ast object. In order to view it, I would like to
transform it to a string but I could not find any method/function for
that.
I would be satisfied if `t2' could be transformed to the corresponding
string. Has anyone implemented a function for that?
Thanks,
Pearu
More information about the Python-list
mailing list