Output difference between ipython and python

后端 未结 1 1264
孤街浪徒
孤街浪徒 2020-12-04 02:32

It was my understanding that python will print the repr of the output, but this is apparently not always the case. For example:

In ipython:

<         


        
相关标签:
1条回答
  • 2020-12-04 03:18

    Instead of repr or standard pprint module IPython uses IPython.lib.pretty.RepresentationPrinter.pretty method to print the output.

    Module IPython.lib.pretty provides two functions that use RepresentationPrinter.pretty behind the scenes.

    IPython.lib.pretty.pretty function returns the string representation of an object:

    >>> from IPython.lib.pretty import pretty
    >>> pretty(type([]))
    'list'
    

    IPython.lib.pretty.pprint function prints the representation of an object:

    >>> from IPython.lib.pretty import pprint
    >>> pprint(type([]))
    list
    

    IPython uses its own pretty printer because the standard Python pprint module "does not allow developers to provide their own pretty print callbacks."

    0 讨论(0)
提交回复
热议问题