如何使 Ipython 输出元素后没有换行符的列表? [英] How to make Ipython output a list without line breaks after elements?
本文介绍了如何使 Ipython 输出元素后没有换行符的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
IPython 控制台打印带有换行符的元素列表,以便每个元素都显示在自己的行中.这通常是一个功能,但在我的情况下它是一个错误:我需要复制和粘贴长列表,所以我需要一个紧凑的表示.我怎样才能做到这一点?
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?
推荐答案
您可以使用 %pprint
命令打开/关闭 pprint 功能:
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]
如果您想永久关闭pprint
,请创建一个配置文件,并将c.PlainTextFormatter.pprint = False
添加到配置文件中.
If you want to turn off pprint
permanently, make a profile, and add c.PlainTextFormatter.pprint = False
to the profile file.
Linux 示例:
$ 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
这篇关于如何使 Ipython 输出元素后没有换行符的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文