Skip to content

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