1 2 3 4 5 6 7 8 9 10 11 12
| >>> data = '''s = '%s%s' % ('o', 's')
... mm = getattr( np.testing.utils, s)
... nm.remove('*')'''
>>> ast.dump(ast.parse(data))
"Module(body=[Assign(targets=[Name(id='s', ctx=Store())], value=BinOp(left=
Str(s='%s%s'), op=Mod(), right=Tuple(elts=[Str(s='o'), Str(s='s')], ctx=Load()))), As
sign(targets=[Name(id='mm', ctx=Store())], value=Call(func=Name(id='getattr', ct
x=Load()), args=[Attribute(value=Attribute(value=Name(id='np', ctx=Load()), attr
='testing', ctx=Load()), attr='utils', ctx=Load()), Name(id='s', ctx=Load())], k
eywords=[], starargs=None, kwargs=None)), Expr(value=Call(func=Attribute(value=N
ame(id='nm', ctx=Load()), attr='remove', ctx=Load()), args=[Str(s='*')], keyword
s=[], starargs=None, kwargs=None))])" |
Partager