summaryrefslogtreecommitdiffstats
path: root/Lib/pickle.py
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-07-27 23:02:38 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-07-27 23:02:38 (GMT)
commit455f7bdc0543fa353d2666f16303b024c5e05155 (patch)
tree8f71b9125d386d23708ff109df3fefdc18aba84f /Lib/pickle.py
parent9a381c7a02022268c1db9c228283e5b533237784 (diff)
downloadcpython-455f7bdc0543fa353d2666f16303b024c5e05155.zip
cpython-455f7bdc0543fa353d2666f16303b024c5e05155.tar.gz
cpython-455f7bdc0543fa353d2666f16303b024c5e05155.tar.bz2
Issue #9378: python -m pickle <pickle file> will now load and display
the first object in the pickle file.
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r--Lib/pickle.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index 372d5b6..8732508 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)