From 773b0091edd3acee7fdb0b42759d2631b515bb35 Mon Sep 17 00:00:00 2001 From: Alexander Belopolsky Date: Tue, 27 Jul 2010 23:02:38 +0000 Subject: Issue #9378: python -m pickle will now load and display the first object in the pickle file. --- Lib/pickle.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'Lib/pickle.py') diff --git a/Lib/pickle.py b/Lib/pickle.py index 372d5b623a..8732508ae2 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -1322,4 +1322,26 @@ def _test(): return doctest.testmod() if __name__ == "__main__": - _test() + import sys, argparse + parser = argparse.ArgumentParser( + description='display contents of the pickle files') + parser.add_argument( + 'pickle_file', type=argparse.FileType('br'), + nargs='*', help='the pickle file') + parser.add_argument( + '-t', '--test', action='store_true', + help='run self-test suite') + parser.add_argument( + '-v', action='store_true', + help='run verbosely; only affects self-test run') + args = parser.parse_args() + if args.test: + _test() + else: + if not args.pickle_file: + parser.print_help() + else: + import pprint + for f in args.pickle_file: + obj = load(f) + pprint.pprint(obj) -- cgit v1.2.1