-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can pprint/pretty be temporarily be disabled? #1646
Comments
Merged
@willmcgugan It almost looks too simple! :-D I would have to try and experiment with it ... I'll see if I can do this right away. |
It works perfectly here! So much simpler too. |
I have tested it with iPython in a terminal as well as in a Jupyter notebook and it works flawlessly. |
Did I solve your problem? Consider sponsoring the ongoing work on Rich and Textual. Or buy me a coffee to say thanks. |
netbsd-srcmastr
pushed a commit
to NetBSD/pkgsrc
that referenced
this issue
Nov 14, 2021
10.13.0 Added Added json.dumps parameters to print_json Textualize/rich#1638 Fixed Fixed an edge case bug when console module try to detect if they are in a tty at the end of a pytest run Fixed a bug where logging handler raises an exception when running with pythonw (related to https://bugs.python.org/issue13807) Fixed issue with TERM env vars that have more than one hyphen Textualize/rich#1640 Fixed missing new line after progress bar when terminal is not interactive Textualize/rich#1606 Fixed exception in IPython when disabling pprint with %pprint Textualize/rich#1646 Fixed issue where values longer than the console width produced invalid JSON Textualize/rich#1653 Fixes trailing comma when pretty printing dataclass with last field repr=False Textualize/rich#1599 Changed Markdown codeblocks now word-wrap
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Discussed in #1603
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
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: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)
in
----> 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] friendly-traceback/friendly#14
The text was updated successfully, but these errors were encountered: