| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Expand Up | @@ -36,7 +36,8 @@ Functions | |||||||||
| --------- | ||||||||||
|
|
||||||||||
| .. function:: pp(object, stream=None, indent=1, width=80, depth=None, *, \ | ||||||||||
| compact=False, sort_dicts=False, underscore_numbers=False) | ||||||||||
| compact=False, sort_dicts=False, underscore_numbers=False, \ | ||||||||||
| block_style=False) | ||||||||||
|
|
||||||||||
| Prints the formatted representation of *object*, followed by a newline. | ||||||||||
| This function may be used in the interactive interpreter | ||||||||||
| Expand Down Expand Up | @@ -85,6 +86,12 @@ Functions | |||||||||
| integers will be formatted with the ``_`` character for a thousands separator, | ||||||||||
| otherwise underscores are not displayed (the default). | ||||||||||
|
|
||||||||||
| :param bool block_style: | ||||||||||
| If ``True``, | ||||||||||
| opening parentheses and brackets will be followed by a newline and the | ||||||||||
| following content will be indented by one level, similar to block style | ||||||||||
| JSON formatting. This option is not compatible with *compact*. | ||||||||||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
A passing thought: Perhaps introduce a mode (str) argument, and deprecate compact in favour of it? It's not great to have two conflicting Booleans, though it may be the best option for now.
Sorry, something went wrong.
All reactions
|
||||||||||
|
|
||||||||||
| >>> import pprint | ||||||||||
| >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] | ||||||||||
| >>> stuff.insert(0, stuff) | ||||||||||
| Expand All | @@ -100,18 +107,20 @@ Functions | |||||||||
|
|
||||||||||
|
|
||||||||||
| .. function:: pprint(object, stream=None, indent=1, width=80, depth=None, *, \ | ||||||||||
| compact=False, sort_dicts=True, underscore_numbers=False) | ||||||||||
| compact=False, sort_dicts=True, \ | ||||||||||
| underscore_numbers=False, block_style=False) | ||||||||||
|
Comment thread
Comment on lines
+110
to
+111
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityLikewise
Suggested change
Sorry, something went wrong.
All reactions
|
||||||||||
|
|
||||||||||
| Alias for :func:`~pprint.pp` with *sort_dicts* set to ``True`` by default, | ||||||||||
| which would automatically sort the dictionaries' keys, | ||||||||||
| you might want to use :func:`~pprint.pp` instead where it is ``False`` by default. | ||||||||||
|
|
||||||||||
|
|
||||||||||
| .. function:: pformat(object, indent=1, width=80, depth=None, *, \ | ||||||||||
| compact=False, sort_dicts=True, underscore_numbers=False) | ||||||||||
| compact=False, sort_dicts=True, \ | ||||||||||
| underscore_numbers=False, block_style=False) | ||||||||||
|
Comment thread
Comment on lines
+119
to
+120
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityLikewise
Suggested change
Sorry, something went wrong.
All reactions
|
||||||||||
|
|
||||||||||
| Return the formatted representation of *object* as a string. *indent*, | ||||||||||
| *width*, *depth*, *compact*, *sort_dicts* and *underscore_numbers* are | ||||||||||
| *width*, *depth*, *compact*, *sort_dicts*, *underscore_numbers* and *block_style* are | ||||||||||
| passed to the :class:`PrettyPrinter` constructor as formatting parameters | ||||||||||
| and their meanings are as described in the documentation above. | ||||||||||
|
|
||||||||||
| Expand Down Expand Up | @@ -155,7 +164,8 @@ PrettyPrinter Objects | |||||||||
| .. index:: single: ...; placeholder | ||||||||||
|
|
||||||||||
| .. class:: PrettyPrinter(indent=1, width=80, depth=None, stream=None, *, \ | ||||||||||
| compact=False, sort_dicts=True, underscore_numbers=False) | ||||||||||
| compact=False, sort_dicts=True, \ | ||||||||||
| underscore_numbers=False, block_style=False) | ||||||||||
|
Comment thread
Comment on lines
+167
to
+168
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityLikewise
Suggested change
Sorry, something went wrong.
All reactions
|
||||||||||
|
|
||||||||||
| Construct a :class:`PrettyPrinter` instance. | ||||||||||
|
|
||||||||||
| Expand All | @@ -179,6 +189,22 @@ PrettyPrinter Objects | |||||||||
| 'knights', 'ni'], | ||||||||||
| 'spam', 'eggs', 'lumberjack', 'knights', | ||||||||||
| 'ni'] | ||||||||||
| >>> pp = pprint.PrettyPrinter(width=41, block_style=True, indent=3) | ||||||||||
| >>> pp.pprint(stuff) | ||||||||||
| [ | ||||||||||
| [ | ||||||||||
| 'spam', | ||||||||||
| 'eggs', | ||||||||||
| 'lumberjack', | ||||||||||
| 'knights', | ||||||||||
| 'ni' | ||||||||||
| ], | ||||||||||
| 'spam', | ||||||||||
| 'eggs', | ||||||||||
| 'lumberjack', | ||||||||||
| 'knights', | ||||||||||
| 'ni' | ||||||||||
| ] | ||||||||||
| >>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', | ||||||||||
| ... ('parrot', ('fresh fruit',)))))))) | ||||||||||
| >>> pp = pprint.PrettyPrinter(depth=6) | ||||||||||
| Expand All | @@ -198,6 +224,9 @@ PrettyPrinter Objects | |||||||||
| .. versionchanged:: 3.11 | ||||||||||
| No longer attempts to write to :data:`!sys.stdout` if it is ``None``. | ||||||||||
|
|
||||||||||
| .. versionchanged:: next | ||||||||||
| Added the *block_style* parameter. | ||||||||||
|
|
||||||||||
|
|
||||||||||
| :class:`PrettyPrinter` instances have the following methods: | ||||||||||
|
|
||||||||||
| Expand Down Expand Up | @@ -420,3 +449,72 @@ cannot be split, the specified width will be exceeded:: | |||||||||
| 'requires_python': None, | ||||||||||
| 'summary': 'A sample Python project', | ||||||||||
| 'version': '1.2.0'} | ||||||||||
|
|
||||||||||
| Lastly, we can achieve block style formatting with the *block_style* parameter. | ||||||||||
| Best results are achieved with a higher *indent* value:: | ||||||||||
|
|
||||||||||
| >>> pprint.pp(project_info, indent=4, block_style=True) | ||||||||||
| { | ||||||||||
| 'author': 'The Python Packaging Authority', | ||||||||||
| 'author_email': 'pypa-dev@googlegroups.com', | ||||||||||
| 'bugtrack_url': None, | ||||||||||
| 'classifiers': [ | ||||||||||
| 'Development Status :: 3 - Alpha', | ||||||||||
| 'Intended Audience :: Developers', | ||||||||||
| 'License :: OSI Approved :: MIT License', | ||||||||||
| 'Programming Language :: Python :: 2', | ||||||||||
| 'Programming Language :: Python :: 2.6', | ||||||||||
| 'Programming Language :: Python :: 2.7', | ||||||||||
| 'Programming Language :: Python :: 3', | ||||||||||
| 'Programming Language :: Python :: 3.2', | ||||||||||
| 'Programming Language :: Python :: 3.3', | ||||||||||
| 'Programming Language :: Python :: 3.4', | ||||||||||
| 'Topic :: Software Development :: Build Tools' | ||||||||||
| ], | ||||||||||
| 'description': 'A sample Python project\n' | ||||||||||
| '=======================\n' | ||||||||||
| '\n' | ||||||||||
| 'This is the description file for the project.\n' | ||||||||||
| '\n' | ||||||||||
| 'The file should use UTF-8 encoding and be written using ReStructured ' | ||||||||||
| 'Text. It\n' | ||||||||||
| 'will be used to generate the project webpage on PyPI, and should be ' | ||||||||||
| 'written for\n' | ||||||||||
| 'that purpose.\n' | ||||||||||
| '\n' | ||||||||||
| 'Typical contents for this file would include an overview of the project, ' | ||||||||||
| 'basic\n' | ||||||||||
| 'usage examples, etc. Generally, including the project changelog in here ' | ||||||||||
| 'is not\n' | ||||||||||
| 'a good idea, although a simple "What\'s New" section for the most recent ' | ||||||||||
| 'version\n' | ||||||||||
| 'may be appropriate.', | ||||||||||
| 'description_content_type': None, | ||||||||||
| 'docs_url': None, | ||||||||||
| 'download_url': 'UNKNOWN', | ||||||||||
| 'downloads': {'last_day': -1, 'last_month': -1, 'last_week': -1}, | ||||||||||
| 'dynamic': None, | ||||||||||
| 'home_page': 'https://github.com/pypa/sampleproject', | ||||||||||
| 'keywords': 'sample setuptools development', | ||||||||||
| 'license': 'MIT', | ||||||||||
| 'license_expression': None, | ||||||||||
| 'license_files': None, | ||||||||||
| 'maintainer': None, | ||||||||||
| 'maintainer_email': None, | ||||||||||
| 'name': 'sampleproject', | ||||||||||
| 'package_url': 'https://pypi.org/project/sampleproject/', | ||||||||||
| 'platform': 'UNKNOWN', | ||||||||||
| 'project_url': 'https://pypi.org/project/sampleproject/', | ||||||||||
| 'project_urls': { | ||||||||||
| 'Download': 'UNKNOWN', | ||||||||||
| 'Homepage': 'https://github.com/pypa/sampleproject' | ||||||||||
| }, | ||||||||||
| 'provides_extra': None, | ||||||||||
| 'release_url': 'https://pypi.org/project/sampleproject/1.2.0/', | ||||||||||
| 'requires_dist': None, | ||||||||||
| 'requires_python': None, | ||||||||||
| 'summary': 'A sample Python project', | ||||||||||
| 'version': '1.2.0', | ||||||||||
| 'yanked': False, | ||||||||||
| 'yanked_reason': None | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| Expand Up | @@ -888,6 +888,16 @@ platform | |||||
| (Contributed by Bénédikt Tran in :gh:`122549`.) | ||||||
|
|
||||||
|
|
||||||
| pprint | ||||||
| ------ | ||||||
|
|
||||||
| * Add a *block_style* keyword argument for :func:`pprint.pprint`, | ||||||
| :func:`pprint.pformat`, :func:`pprint.pp`. If true, the output will be | ||||||
| formatted in a block style similar to pretty-printed :func:`json.dumps` when | ||||||
| *indent* is supplied. | ||||||
| (Contributed by Stefan Todoran in :gh:`129274`.) | ||||||
|
Comment thread
StefanTodoran marked this conversation as resolved.
|
||||||
|
|
||||||
|
|
||||||
| pydoc | ||||||
| ----- | ||||||
|
|
||||||
| Expand Down Expand Up | @@ -1200,7 +1210,7 @@ Deprecated | |||||
| .. include:: ../deprecations/pending-removal-in-future.rst | ||||||
|
|
||||||
| Removed | ||||||
| ======= | ||||||
| ======== | ||||||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
Sorry, something went wrong.
All reactions
|
||||||
|
|
||||||
| argparse | ||||||
| -------- | ||||||
| Expand Down | ||||||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThese are keyword-only (after *), so we have the luxury of alphabetical sorting:
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.