question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can pprint/pretty be temporarily be disabled?

See original GitHub issue

Discussed in https://github.com/willmcgugan/rich/discussions/1603

<div type='discussions-op-text'>

Originally posted by aroberge October 16, 2021 This question came as the result of an issue [1] filed in one of my projects.

When using IPython (on its own), it is possible to toggle on and off the pretty printing. For example, doing

dir(__builtins__)
In [1]: dir(__builtins__)
Out[1]:
['ArithmeticError',
 'AssertionError',
 'AttributeError',
 'BaseException',
 'BlockingIOError',
 'BrokenPipeError',
 'BufferError',
 'BytesWarning',
 'ChildProcessError',
 'ConnectionAbortedError',
 'ConnectionError',
...

outputs names one at a time on a line. However, after turning off the pretty printing with the magic command %pprint, the display is shown without pretty formatting:

In [2]: %pprint
Pretty printing has been turned OFF

In [3]: dir(__builtins__)
Out[3]: ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', ...

When using Rich with IPython, attempting to use the magic toggle %pprint results in a traceback. In [4]: from rich import pretty

In [5]: pretty.install()

In [6]: %pprint

AttributeError Traceback (most recent call last) <ipython-input-6-1efe34cfb034> in <module> ----> 1 get_ipython().run_line_magic(‘pprint’, ‘’) 306 “”“Toggle pretty printing on/off.”“” 307 ptformatter = self.shell.display_formatter.formatters[‘text/plain’] –> 308 ptformatter.pprint = bool(1 - ptformatter.pprint) 309 print(‘Pretty printing has been turned’, 310 [‘OFF’,‘ON’][ptformatter.pprint])

AttributeError: ‘BaseFormatter’ object has no attribute ‘pprint’ …

Looking at the source code for Rich, this is not surprising since I can see that it monkeypatches IPython’s code, substituting its own pretty printer.

I am wondering if there is a way to (temporarily) disable Rich’s pretty printer once it is installed.

[1] https://github.com/friendly-traceback/friendly/issues/14</div>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
arobergecommented, Nov 6, 2021

It works perfectly here! So much simpler too.

0reactions
github-actions[bot]commented, Nov 6, 2021

Did I solve your problem?

Consider sponsoring the ongoing work on Rich and Textual.

Or buy me a coffee to say thanks.

Will McGugan

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can pprint/pretty be temporarily be disabled? #1646 - GitHub
I am wondering if there is a way to (temporarily) disable Rich's pretty printer once it is installed. [1] friendly-traceback/friendly#14.
Read more >
Disabling sorting mechanism in pprint output - Stack Overflow
You can subclass PrettyPrinter and remove the sorted(object.items()) from _pprint_dict .
Read more >
pprint — Data pretty printer — Python 3.11.1 documentation
The pprint module provides a capability to “pretty-print” arbitrary Python data structures in a form which can be used as input to the...
Read more >
Temporarily disable print areas in Excel - AuditExcel
Temporarily disable print areas in MS Excel so that for one print only you can print the whole sheet, but the print areas...
Read more >
Temporarily disable SSH for all users except one and print a ...
nisse is my admin(su) user that I will be using to access the server during the upgrade. The problem is that I want...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found