如何使Ipython在列表后没有换行符的情况下输出列表? [英] How to make Ipython output a list without line breaks after elements?

查看:155
本文介绍了如何使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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆