gaogaotiantian / objprint

A library that can print Python objects in human readable format
Apache License 2.0
510 stars 43 forks source link

weird escaped characters in jupyter notebook's output #61

Closed Asuralf closed 2 years ago

Asuralf commented 2 years ago

I used pyreadstat module to read a simple SAS file. the code goes like this in jupyter notebook

import pyreadstat as pyrs
from objprint import op

sas_path = './test_sas/foo.sas7bdat'
df, meta = pyrs.read_sas7bdat(sas_path, metadataonly=True)
# just wanted to check out what meta contains 
op(meta)

the brief output of current cell seems normal

Output exceeds the [size limit]. Open the full output data[ in a text editor]
<metadata_container 0x1bcf4bfa3e0
  .column_labels = [
    'projectid',
    'project',
...
    'project': '$'
  },
  .variable_value_labels = {}
>
<pyreadstat._readstat_parser.metadata_container at 0x1bcf4bfa3e0>

but after I clicked "in a text editor", the first lines look like this:

<metadata_container 0x1bcf4bfa3e0
  .column_labels = [
    'projectid',
    'project',

the weird characters actually look like small suqares contains 3 small letters ESC in the text editor.

gaogaotiantian commented 2 years ago

Those are the ANSI escape characters to colorize the output. If you directly open that in the editor it could output this weird stuff. The simple way to solve this is to simply add color=False as an argument in op(). You could also set it globally by op.config(color=False)

Asuralf commented 2 years ago

thanks, it works