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

Skip to content

Commit ce0c19c

Browse files
committed
Only print attributes that start with co_.
If passed a .py file as an argument, try to find its accompanying .pyc.
1 parent 37c9351 commit ce0c19c

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Tools/compiler/dumppyc.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#! /usr/bin/env python
22

33
import marshal
4+
import os
45
import dis
56
import types
67

78
def dump(obj):
89
print obj
910
for attr in dir(obj):
10-
print "\t", attr, repr(getattr(obj, attr))
11+
if attr.startswith('co_'):
12+
val = getattr(obj, attr)
13+
print "\t", attr, repr(val)
1114

1215
def loadCode(path):
1316
f = open(path)
@@ -36,4 +39,6 @@ def main(filename, codename=None):
3639
else:
3740
filename = sys.argv[1]
3841
codename = None
42+
if filename.endswith('.py') and os.path.exists(filename+"c"):
43+
filename += "c"
3944
main(filename, codename)

0 commit comments

Comments
 (0)