本文整理匯總了Python中ast.Print方法的典型用法代碼示例。如果您正苦於以下問題:Python ast.Print方法的具體用法?Python ast.Print怎麽用?Python ast.Print使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ast
的用法示例。
在下文中一共展示了ast.Print方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parse
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Print [as 別名]
def parse(self):
@self.pg.production('program : PRINT OPEN_PAREN expression CLOSE_PAREN SEMI_COLON')
def program(p):
return Print(self.builder, self.module, self.printf, p[2])
@self.pg.production('expression : expression SUM expression')
@self.pg.production('expression : expression SUB expression')
def expression(p):
left = p[0]
right = p[2]
operator = p[1]
if operator.gettokentype() == 'SUM':
return Sum(self.builder, self.module, left, right)
elif operator.gettokentype() == 'SUB':
return Sub(self.builder, self.module, left, right)
@self.pg.production('expression : NUMBER')
def number(p):
return Number(self.builder, self.module, p[0].value)
@self.pg.error
def error_handle(token):
raise ValueError(token)
示例2: onelinerize
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Print [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)
示例3: p_print_stmt_1
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Print [as 別名]
def p_print_stmt_1(p):
'''print_stmt : PRINT'''
# 1
p[0] = ast.Print(None, [], True, rule=inspect.currentframe().f_code.co_name, **p[1][1])
示例4: p_print_stmt_2
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Print [as 別名]
def p_print_stmt_2(p):
'''print_stmt : PRINT test'''
# 1 2
p[0] = ast.Print(None, [p[2]], True, rule=inspect.currentframe().f_code.co_name, **p[1][1])
示例5: p_print_stmt_3
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Print [as 別名]
def p_print_stmt_3(p):
'''print_stmt : PRINT test COMMA'''
# 1 2 3
p[0] = ast.Print(None, [p[2]], False, rule=inspect.currentframe().f_code.co_name, **p[1][1])
示例6: p_print_stmt_4
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Print [as 別名]
def p_print_stmt_4(p):
'''print_stmt : PRINT test print_stmt_plus'''
# 1 2 3
p[0] = ast.Print(None, [p[2]] + p[3], True, rule=inspect.currentframe().f_code.co_name, **p[1][1])
示例7: p_print_stmt_5
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Print [as 別名]
def p_print_stmt_5(p):
'''print_stmt : PRINT test print_stmt_plus COMMA'''
# 1 2 3 4
p[0] = ast.Print(None, [p[2]] + p[3], False, rule=inspect.currentframe().f_code.co_name, **p[1][1])
示例8: p_print_stmt_7
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Print [as 別名]
def p_print_stmt_7(p):
'''print_stmt : PRINT RIGHTSHIFT test print_stmt_plus'''
# 1 2 3 4
p[0] = ast.Print(p[3], p[4], True, rule=inspect.currentframe().f_code.co_name, **p[1][1])
示例9: p_print_stmt_8
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Print [as 別名]
def p_print_stmt_8(p):
'''print_stmt : PRINT RIGHTSHIFT test print_stmt_plus COMMA'''
# 1 2 3 4 5
p[0] = ast.Print(p[3], p[4], False, rule=inspect.currentframe().f_code.co_name, **p[1][1])
示例10: func_check
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Print [as 別名]
def func_check(node, kw=False):
'''
Function specific check
Action - check return type
Action - check pstep/psubstep buddy with report_step/report_substep_status
check docstring
check print statement - should use print_utils
scan for class - class check
scan for function - recursive function check
'''
status = True
have_return = False
substep_count = 0
# investigate everything in a function
for child in ast.walk(node):
if child != node and isinstance(child, ast.FunctionDef):
# check for private method in action file
if kw and child.name.startswith("_"):
print node.name, child.name, "should move to utils"
status = False
tmp_status = func_check(child, kw)
status &= tmp_status
elif child != node and isinstance(child, ast.ClassDef):
tmp_status = class_check(child, kw)
status &= tmp_status
elif 'war_print_class.py' not in sys.argv[1] and isinstance(child, ast.Print):
# check for print statement
status = False
print "Please use print_Utils instead of print in {}: {}".format(
sys.argv[1], child.lineno)
elif isinstance(child, ast.Return):
# check for return statement
have_return = True
elif isinstance(child, ast.Attribute) and child.attr == 'pSubStep':
# check for Substep and report substep pair
substep_count += 1
elif isinstance(child, ast.Attribute) and child.attr == 'report_substep_status':
substep_count -= 1
if ast.get_docstring(node) is None:
print node.name, "doesn't contain any docstring"
status = False
if kw and not have_return and node.name != "__init__":
print node.name, "doesn't contain a return statement"
status = False
if kw and substep_count:
print node.name, "have non-pair pSubStepreport_substep_status"
status = False
return status