在接受用户输入后,如何防止Spyder插入新行? [英] How can I prevent Spyder from inserting a new line after taking user input?

查看:81
本文介绍了在接受用户输入后,如何防止Spyder插入新行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spyder在每次调用input()函数之间的控制台输出中插入空白行,但我不希望这样做(即,我希望input()提示位于控制台中的连续行上,而不是用逗号分隔空行).有没有办法做到这一点?我尝试使用input("foo", end="")认为它可能像print()函数一样工作,但事实并非如此...

Spyder inserts a blank line in the console output between every call of the input() function but I don't want that (i.e. I want the input() prompts to be on contiguous lines in the console instead of separated by a blank line). Is there a way to do that? I tried using input("foo", end="") thinking it may work like the print() function but that's not the case...

代码:

fname = input("Please enter your first name: ")
lname = input("Please enter your last name: ")
print("Pleased to meet you, " + str(fname) + " " + str(lname) + "!")

输出:

Please enter your first name: Jane

Please enter your last name: Doe
Pleased to meet you, Jane Doe!

所需的输出:

Please enter your first name: Jane
Please enter your last name: Doe
Pleased to meet you, Jane Doe!

正如其他人在评论部分中指出的那样,除了在Spyder IDE中使用IPython接口之外,这个问题对我来说都是不可重现的.如果有人在Spyder之外运行IPython,请运行上面的代码,并让我知道是否产生相同的输出.我可以通过Spyder的IPython界面(而不是通过Terminal会话)来复制不需要的输出,所以这是IPython或Spyder特有的.

As others have pointed out in the comments section, this issue is non-reproducible, even for me, except through the use of the IPython interface within the Spyder IDE. If anyone is running IPython outside of Spyder, please run the above code and let me know whether that produces the same output. I can reproduce the undesired output through Spyder's IPython interface but not through a Terminal session so this is something specific to either IPython or Spyder.

推荐答案

(此处为 Spyder开发人员),这看起来像是我们IPython控制台中的一个小错误.请在这里报告:

(Spyder developer here) This looks like a minor bug in our IPython console. Please report it here:

https://github.com/jupyter/qtconsole

注意:该控制台并非只是将终端IPython会话嵌入Spyder中(这就是为什么对此进行比较完全没有意义的原因).

Note: This console is not simply embedding a terminal IPython session in Spyder (that's why making comparisons to it make no sense at all).

相反,它是大多数终端行为的重新实现,但使用图形工具包(称为Qt)和Jupyter内核/前端体系结构.

Instead, it is a re-implementation of most of the terminal behavior but using a graphical toolkit (called Qt) and the Jupyter kernel/frontend architecture.

这篇关于在接受用户输入后,如何防止Spyder插入新行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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