Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-93096: Update and documentpickle CLI#131097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 17 commits intopython:mainfromdonBarbos:issue-93096-pickle-cli-docs
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from10 commits
Commits
Show all changes
17 commits
Select commitHold shift + click to select a range
f572b59
Add CLI docs for `pickle`
donBarbosMar 11, 2025
923af7b
Correct ref preview
donBarbosMar 11, 2025
5909db4
Update Doc/library/pickle.rst
donBarbosMar 12, 2025
291f6bf
Add suggestions
donBarbosMar 13, 2025
215afa9
Fix typo
donBarbosMar 13, 2025
3b8efae
Update doc
donBarbosMar 13, 2025
40a3265
Fix pickle parser
donBarbosMar 13, 2025
c93b70f
Add feature
donBarbosMar 13, 2025
cefd8a4
Update Doc/library/pickle.rst
donBarbosMar 13, 2025
4bc3253
Move cli section
donBarbosMar 13, 2025
29d1360
Update Doc/library/pickle.rst
donBarbosMar 14, 2025
3dd66f2
Update Lib/pickle.py
donBarbosMar 14, 2025
ff22e97
back sort_dicts=True
donBarbosMar 14, 2025
dbedc68
pprint.pp(obj)
hugovkMar 14, 2025
756ff98
Merge branch 'main' into issue-93096-pickle-cli-docs
donBarbosMar 14, 2025
593fd7b
Revert using pp
donBarbosMar 14, 2025
8f1af6e
Update Lib/pickle.py
donBarbosMar 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionDoc/library/cmdline.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,7 @@ The following modules have a command-line interface.
* :ref:`json <json-commandline>`
* :mod:`mimetypes`
* :mod:`pdb`
* :mod:`pickle`
* :ref:`pickle <pickle-cli>`
* :ref:`pickletools <pickletools-cli>`
* :mod:`platform`
* :mod:`poplib`
Expand Down
24 changes: 24 additions & 0 deletionsDoc/library/pickle.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1210,6 +1210,30 @@ The following example reads the resulting pickled data. ::
.. pickletools.optimize() or the gzip module).


.. _pickle-cli:

Command-line interface
----------------------

The :mod:`pickle` module can be invoked as a script from the command line,
it will display contents of the pickle files. However, when the pickle file
that you want to examine comes from an untrusted source, ``-m pickletools``
is a safer option because it does not execute pickle bytecode, see
:ref:`pickletools CLI usage <pickletools-cli>`.

.. code-block:: bash

python -m pickle pickle_file [pickle_file ...]

The following option is accepted:

.. program:: pickle

.. option:: pickle_file

A pickle file to read or ``-`` to indicate reading from standard input.


.. seealso::

Module :mod:`copyreg`
Expand Down
21 changes: 9 additions & 12 deletionsLib/pickle.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1909,20 +1909,17 @@ def _loads(s, /, *, fix_imports=True, encoding="ASCII", errors="strict",

if __name__ == "__main__":
import argparse
import pprint
parser = argparse.ArgumentParser(
description='display contents of the pickle files')
parser.add_argument(
'pickle_file',
nargs='*', help='the pickle file')
nargs='+', help='the pickle file')
args = parser.parse_args()
if not args.pickle_file:
parser.print_help()
else:
import pprint
for fn in args.pickle_file:
if fn == '-':
obj = load(sys.stdin.buffer)
else:
with open(fn, 'rb') as f:
obj = load(f)
pprint.pprint(obj)
for fn in args.pickle_file:
if fn == '-':
obj = load(sys.stdin.buffer)
else:
with open(fn, 'rb') as f:
obj = load(f)
pprint.pprint(obj)
Loading

[8]ページ先頭

©2009-2025 Movatter.jp