本文整理汇总了Python中ast.Exec方法的典型用法代码示例。如果您正苦于以下问题:Python ast.Exec方法的具体用法?Python ast.Exec怎么用?Python ast.Exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ast
的用法示例。
在下文中一共展示了ast.Exec方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onelinerize
# 需要导入模块: import ast [as 别名]
# 或者: from ast import Exec [as 别名]
def onelinerize(original):
# original :: string
# :: string
t = ast.parse(original)
table = symtable.symtable(original, '<string>', 'exec')
original = original.strip()
# If there's only one line anyways, be lazy
if len(original.splitlines()) == 1 and \
len(t.body) == 1 and \
type(t.body[0]) in (ast.Delete, ast.Assign, ast.AugAssign, ast.Print,
ast.Raise, ast.Assert, ast.Import, ast.ImportFrom,
ast.Exec, ast.Global, ast.Expr, ast.Pass):
return original
return get_init_code(t, table)
示例2: supports_feature
# 需要导入模块: import ast [as 别名]
# 或者: from ast import Exec [as 别名]
def supports_feature(feature):
if feature == 'bytes_node':
return hasattr(ast, 'Bytes') and issubclass(ast.Bytes, ast.AST)
if feature == 'exec_node':
return hasattr(ast, 'Exec') and issubclass(ast.Exec, ast.AST)
if feature == 'type_annotations':
try:
ast.parse('def foo(bar: str=123) -> None: pass')
except SyntaxError:
return False
return True
if feature == 'fstring':
return hasattr(ast, 'JoinedStr') and issubclass(ast.JoinedStr, ast.AST)
# Python 2 counts tabs as 8 spaces for indentation
if feature == 'mixed_tabs_spaces':
return sys.version_info[0] < 3
return False
示例3: p_exec_stmt_1
# 需要导入模块: import ast [as 别名]
# 或者: from ast import Exec [as 别名]
def p_exec_stmt_1(p):
'''exec_stmt : EXEC expr'''
# 1 2
p[0] = ast.Exec(p[2], None, None, rule=inspect.currentframe().f_code.co_name, **p[1][1])
示例4: p_exec_stmt_2
# 需要导入模块: import ast [as 别名]
# 或者: from ast import Exec [as 别名]
def p_exec_stmt_2(p):
'''exec_stmt : EXEC expr IN test'''
# 1 2 3 4
p[0] = ast.Exec(p[2], p[4], None, rule=inspect.currentframe().f_code.co_name, **p[1][1])
示例5: p_exec_stmt_3
# 需要导入模块: import ast [as 别名]
# 或者: from ast import Exec [as 别名]
def p_exec_stmt_3(p):
'''exec_stmt : EXEC expr IN test COMMA test'''
# 1 2 3 4 5 6
p[0] = ast.Exec(p[2], p[4], p[6], rule=inspect.currentframe().f_code.co_name, **p[1][1])
# assert_stmt: 'assert' test [',' test]