當前位置: 首頁>>代碼示例>>Python>>正文


Python ast.Exec方法代碼示例

本文整理匯總了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) 
開發者ID:csvoss,項目名稱:onelinerizer,代碼行數:19,代碼來源:onelinerizer.py

示例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 
開發者ID:google,項目名稱:pasta,代碼行數:19,代碼來源:test_utils.py

示例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]) 
開發者ID:histogrammar,項目名稱:histogrammar-python,代碼行數:6,代碼來源:hgawk_grammar.py

示例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]) 
開發者ID:histogrammar,項目名稱:histogrammar-python,代碼行數:6,代碼來源:hgawk_grammar.py

示例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] 
開發者ID:histogrammar,項目名稱:histogrammar-python,代碼行數:8,代碼來源:hgawk_grammar.py


注:本文中的ast.Exec方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。