Skip to content
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

Use sys.displayhook for converting result to string #570

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bogdan-nikitin
Copy link

Fix for #488

Some libraries, like SymPy, redefine sys.displayhook to change printing behavior.

Use sys.displayhook to convert the result to a string in OutputPrinter._format_result_output.

@CharlesJQuarra
Copy link

CharlesJQuarra commented Nov 8, 2024

Just tested this on ubuntu 20.04 / conda 24.9 / python 3.8.18 and it works great. What's the holdup for not merging this?

@CharlesJQuarra
Copy link

CharlesJQuarra commented Nov 8, 2024

One observation I have: the output always wraps for me at 78 characters, even if the terminal window is wider than that. If I override num_columns default in sympy.init_printing() and set a higher value, the wrap happens correctly. Not sure if this is a prompt-toolkit issue or sympy, but it only happens using ptpython.repl.embed, not the default REPL

In particular the following solves the wrapping issue for me:

import sympy as sp
from shutil import get_terminal_size

sp.init_printing(num_columns=get_terminal_size()[0])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants