diff options
author | Guido van Rossum <guido@python.org> | 2000-02-04 17:47:55 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-02-04 17:47:55 (GMT) |
commit | 1fdae12c93246fcf4abbf882ba08df789070dfcc (patch) | |
tree | 1a2d597068b2c16bc9a1aa667e6d1e3296777c44 /Lib/dis.py | |
parent | 4b8c6eaf8b287a27e0054cf6c751448b2077e83b (diff) | |
download | cpython-1fdae12c93246fcf4abbf882ba08df789070dfcc.zip cpython-1fdae12c93246fcf4abbf882ba08df789070dfcc.tar.gz cpython-1fdae12c93246fcf4abbf882ba08df789070dfcc.tar.bz2 |
Added a simple test program to disassemble a file, invoked as __main__.
Diffstat (limited to 'Lib/dis.py')
-rw-r--r-- | Lib/dis.py | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -251,3 +251,30 @@ def_op('RAISE_VARARGS', 130) def_op('CALL_FUNCTION', 131) def_op('MAKE_FUNCTION', 132) def_op('BUILD_SLICE', 133) + + +def _test(): + """Simple test program to disassemble a file.""" + if sys.argv[1:]: + if sys.argv[2:]: + sys.stderr.write("usage: python dis.py [-|file]\n") + sys.exit(2) + fn = sys.argv[1] + if not fn or fn == "-": + fn = None + else: + fn = None + if not fn: + f = sys.stdin + else: + f = open(fn) + source = f.read() + if fn: + f.close() + else: + fn = "<stdin>" + code = compile(source, fn, "exec") + dis(code) + +if __name__ == "__main__": + _test() |