pythonpython-3.xvisual-studio-codejupyter-notebook

VS Code text output unreadable format in new window


I was using a jupyter notebook inside VSCode and used ?? on the object to look the source code. The output showed : enter image description here

Output exceeds the size limit. Open the full output data in a text editor

But when I click on it it opens the output in another window but everything is illegible.

enter image description here

What's going on here? What are those strange characters like esc[031m? How can I get rid of them when viewing the full output data?


Solution

  • Those are ANSI escape codes- particularly ones for colouring.

    If ANSI color support in edit buffer #38834 gets implemented, then this problem will sort of "go away" by default (though I imagine it could lead to different kinds of confusion).

    The IPython configuration docs have a section on terminal colours:

    InteractiveShell.colors sets the colour of tracebacks and object info (the output from e.g. zip?). It may also affect other things if the option below is set to 'legacy'. It has four case-insensitive values: 'nocolor', 'neutral', 'linux', 'lightbg'. The default is neutral, which should be legible on either dark or light terminal backgrounds. linux is optimised for dark backgrounds and lightbg for light ones.

    See the rest of those docs for more info.

    Ideally, the VS Code extension for IPython would strip out those ANSI escape sequences when showing the full output data in a text editor, but for now, you may be able to work around that by manual configuration by setting InteractiveShell.colors to 'nocolor', or putting the following code cell at the start of your notebook: %colors nocolor (see related docs here).

    This problem has been brought up on the microsoft/vscode-jupyter GitHub repo at least twice: