Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Ipython output a list without line breaks after elements?

The IPython console prints a list of elements with line breaks so that each element is displayed in its own line. This is usually a feature, but in my case it is a bug: I need to copy and paste long lists, so I need a compact representation. How can I achieve this?

like image 470
clstaudt Avatar asked Sep 25 '13 16:09

clstaudt


1 Answers

You can use %pprint command to turn on/off pprint feature:

In [1]: range(24) Out[1]: [0,  1,  2,  ...  21,  22,  23]  In [2]: %pprint Pretty printing has been turned OFF  In [3]: range(24) Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23] 

If you want to turn off pprint permanently, make a profile, and add c.PlainTextFormatter.pprint = False to the profile file.

Linux example:

$ ipython profile create [ProfileCreate] Generating default config file: '.../ipython_config.py' [ProfileCreate] Generating default config file: u'..../ipython_notebook_config.py' $ echo 'c.PlainTextFormatter.pprint = False' >> ~/.ipython/profile_default/ipython_config.py 
like image 148
falsetru Avatar answered Oct 01 '22 03:10

falsetru