From acc75de4efb12828f489d191febce56c918f8430 Mon Sep 17 00:00:00 2001 From: "Taihsiang Ho (tai271828)" Date: Sun, 28 Nov 2021 11:07:58 +0100 Subject: [PATCH] feat(Lib): print the disassembled info Issue: #2889 --- Lib/dis.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Lib/dis.py b/Lib/dis.py index 421446e0a1..53c85555bc 100644 --- a/Lib/dis.py +++ b/Lib/dis.py @@ -1 +1,18 @@ from _dis import * + + +# Disassembling a file by following cpython Lib/dis.py +def _test(): + """Simple test program to disassemble a file.""" + import argparse + + parser = argparse.ArgumentParser() + parser.add_argument('infile', type=argparse.FileType('rb'), nargs='?', default='-') + args = parser.parse_args() + with args.infile as infile: + source = infile.read() + code = compile(source, args.infile.name, "exec") + dis(code) + +if __name__ == "__main__": + _test()