python - PyCharm 中 IPython 的奇怪 'print' 行为

标签 python terminal pycharm ipython

<分区>

print 函数似乎减少了显示时的点数:

Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 7.22.0
Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0] on linux

In [2]: s = "A\n..... a\n..... b\n"

In [3]: print(s)
A
.. a
.. b


In [4]: 

在终端中不会发生这样的事情:

Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> s = "A\n..... a\n..... b\n"
>>> print(s)
A
..... a
..... b
>>> 

即使我在其中运行 IPython:

$ ipython

Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: s = "A\n..... a\n..... b\n"

In [2]: print(s)
A
..... a
..... b


In [3]: 

有人知道这种行为的原因吗?

最佳答案

我认为这与隐式行连接的 iPython 语法有关。 PyCharm 可能会将三个点转换为省略号,并将其解释为“换行命令”(就像在 ipython 控制台中您在没有右括号的情况下换行并且它期望其他参数)

关于python - PyCharm 中 IPython 的奇怪 'print' 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72198827/

相关文章:

python-3.x - 如何将 WebDriver 转移到导入的测试?

Python:执行Windows Tracert

python - Python 中的 Unicode 全角到标准 ASCII(反之亦然)

bash - 如何使我的 shell 脚本可执行

macos - OS X 的 Perl 和 CPAN 升级帮助

python - 模块未找到错误 : No module named 'distutils.core'

python - boxsizer 内的 wxpython 笔记本

python - aiohttp:设置每秒最大请求数

linux - 获取 tmux 中其他 Pane 的标准输入

postgresql - 在 mac os 中找不到 PostGIS 扩展(安装在不同的目录中)和 $libdir/postgis-2.3