本文整理匯總了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]