Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 18aef3c

Browse files
committed
Support disassembly of a variety of objects through dis.dis().
1 parent 7b7c578 commit 18aef3c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lib/dis.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,27 @@
22

33
import sys
44
import string
5+
import types
56

67
def dis(x=None):
78
if not x:
89
distb()
10+
return
11+
if type(x) is types.InstanceType:
12+
x = x.__class__
13+
if hasattr(x, '__dict__'):
14+
items = x.__dict__.items()
15+
items.sort()
16+
for name, x1 in items:
17+
if type(x1) in (types.MethodType,
18+
types.FunctionType,
19+
types.CodeType):
20+
print "Disassembly of %s:" % name
21+
try:
22+
dis(x1)
23+
except TypeError, msg:
24+
print "Sorry:", msg
25+
print
926
else:
1027
if hasattr(x, 'im_func'):
1128
x = x.im_func

0 commit comments

Comments
 (0)