本文整理汇总了Python中compiler.transformer.parse方法的典型用法代码示例。如果您正苦于以下问题:Python transformer.parse方法的具体用法?Python transformer.parse怎么用?Python transformer.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类compiler.transformer
的用法示例。
在下文中一共展示了transformer.parse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testMultipleLHS
# 需要导入模块: from compiler import transformer [as 别名]
# 或者: from compiler.transformer import parse [as 别名]
def testMultipleLHS(self):
""" Test multiple targets on the left hand side. """
snippets = ['a, b = 1, 2',
'(a, b) = 1, 2',
'((a, b), c) = (1, 2), 3']
for s in snippets:
a = transformer.parse(s)
self.assertIsInstance(a, ast.Module)
child1 = a.getChildNodes()[0]
self.assertIsInstance(child1, ast.Stmt)
child2 = child1.getChildNodes()[0]
self.assertIsInstance(child2, ast.Assign)
# This actually tests the compiler, but it's a way to assure the ast
# is correct
c = compile(s, '<string>', 'single')
vals = {}
exec c in vals
assert vals['a'] == 1
assert vals['b'] == 2
示例2: testMultipleLHS
# 需要导入模块: from compiler import transformer [as 别名]
# 或者: from compiler.transformer import parse [as 别名]
def testMultipleLHS(self):
""" Test multiple targets on the left hand side. """
snippets = ['a, b = 1, 2',
'(a, b) = 1, 2',
'((a, b), c) = (1, 2), 3']
for s in snippets:
a = transformer.parse(s)
assert isinstance(a, ast.Module)
child1 = a.getChildNodes()[0]
assert isinstance(child1, ast.Stmt)
child2 = child1.getChildNodes()[0]
assert isinstance(child2, ast.Assign)
# This actually tests the compiler, but it's a way to assure the ast
# is correct
c = compile(s, '<string>', 'single')
vals = {}
exec c in vals
assert vals['a'] == 1
assert vals['b'] == 2