Skip to content

Commit c93b70f

Browse files
committed
Add feature
1 parent 40a3265 commit c93b70f

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Doc/library/pickle.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,12 @@ The following option is accepted:
532532

533533
.. option:: pickle_file
534534

535-
A pickle file.
535+
A pickle file, which can be a regular filename or a filepath.
536+
Additionally, you can use ``-`` to read from standard input (stdin).
537+
For example, you can pipe a pickle file to the script using a command like:
538+
539+
.. code-block:: bash
540+
echo ... | python -m pickle -
536541
537542
538543
.. _pickle-picklable:

Lib/pickle.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,20 +1909,17 @@ def _loads(s, /, *, fix_imports=True, encoding="ASCII", errors="strict",
19091909

19101910
if __name__ == "__main__":
19111911
import argparse
1912+
import pprint
19121913
parser = argparse.ArgumentParser(
19131914
description='display contents of the pickle files')
19141915
parser.add_argument(
19151916
'pickle_file',
19161917
nargs='+', help='the pickle file')
19171918
args = parser.parse_args()
1918-
if not args.pickle_file:
1919-
parser.print_help()
1920-
else:
1921-
import pprint
1922-
for fn in args.pickle_file:
1923-
if fn == '-':
1924-
obj = load(sys.stdin.buffer)
1925-
else:
1926-
with open(fn, 'rb') as f:
1927-
obj = load(f)
1928-
pprint.pprint(obj)
1919+
for fn in args.pickle_file:
1920+
if fn == '-':
1921+
obj = load(sys.stdin.buffer)
1922+
else:
1923+
with open(fn, 'rb') as f:
1924+
obj = load(f)
1925+
pprint.pprint(obj)

0 commit comments

Comments
 (0)