本文整理匯總了Python中dis.show_code方法的典型用法代碼示例。如果您正苦於以下問題:Python dis.show_code方法的具體用法?Python dis.show_code怎麽用?Python dis.show_code使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dis
的用法示例。
在下文中一共展示了dis.show_code方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: case
# 需要導入模塊: import dis [as 別名]
# 或者: from dis import show_code [as 別名]
def case(code, ctx, debug=False, cpython_compat=True):
stmt = parse(code).result
code_obj = py_compile(stmt, is_entrypoint=False)
if debug:
with open('out_yapypy_bc.log', 'w') as yapypy_bc, open('out_yapypy_info.log',
'w') as yapypy_info:
dis_code(code_obj, yapypy_bc)
show_code(code_obj, yapypy_info)
if cpython_compat:
code_obj2 = compile(code, "", "exec")
with open('out_cpy_bc.log', 'w') as cpy_bc, open('out_cpy_info.log',
'w') as cpy_info:
dis_code(code_obj2, cpy_bc)
show_code(code_obj2, cpy_info)
print('python:')
exec(Bytecode.from_code(code_obj2).to_code(), ctx or {})
print('yapypy')
exec(Bytecode.from_code(code_obj).to_code(), ctx or {})
else:
exec(code_obj, ctx)
示例2: show_code
# 需要導入模塊: import dis [as 別名]
# 或者: from dis import show_code [as 別名]
def show_code(code: types.CodeType, f, contains=()):
if code in contains:
return
f.write('\n\n\n')
f.write(code.co_name)
f.write(':\n\n')
dis.show_code(code, file=f)
for each in code.co_consts:
if isinstance(each, types.CodeType):
show_code(each, f, (*contains, code))
示例3: test_show_code
# 需要導入模塊: import dis [as 別名]
# 或者: from dis import show_code [as 別名]
def test_show_code(self):
self.maxDiff = 1000
for x, expected in self.test_pairs:
with captured_stdout() as output:
dis.show_code(x)
self.assertRegex(output.getvalue(), expected+"\n")
output = io.StringIO()
dis.show_code(x, file=output)
self.assertRegex(output.getvalue(), expected)