为什么日食+ pydev print() 输出看起来很奇怪,有两个字符串?
干草,我刚刚做了以下操作:
a = input("give a word: ")
b = input("give another word: ")
c = a + " " + b
print("result is", c)
并得到如下输出:
give a word: name
give another word: word
result is name
word
我的问题是为什么 pydev 或 eclipse 控制台上的输出分为两行?我期望输出如下:
give a word: name
give another word: word
result is name word
这种情况如何以及为什么发生在我身上?在 cmd 上看起来不错???!
我还发现 python 用“\r”保存字符串,我认为这是在 pydev 控制台上造成这个问题的原因,是吗?
hay all, I just did the following:
a = input("give a word: ")
b = input("give another word: ")
c = a + " " + b
print("result is", c)
and get the output as follows:
give a word: name
give another word: word
result is name
word
my question is why the output on pydev or eclipse console in two lines? i expected to output as follows:
give a word: name
give another word: word
result is name word
how and why this happens to me? on cmd its looking fine??!!
also i found that python saves the strings with "\r", i think that is the one making this problem on pydev console, is it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,Eclipse + PyDev 也在字符串中存储换行符。根据操作系统的不同,换行符有几种变体:\n、\r、\r\n。
无论如何,我认为以下内容应该可以解决您的问题:
我已经在 Windows7 上的 Eclipse Galileo 的 PyDev 上测试了这段代码,它可以工作。
希望这有帮助
It seems to me that Eclipse + PyDev is storing the newline character in the string as well. There are a few variants of the newline character depending on the operating system: \n, \r, \r\n.
In any case, I think the following should fix your problem:
I have tested this code on PyDev for Eclipse Galileo on Windows7 and it works.
Hope this helps
这很奇怪。
您是否在单词后收到额外的换行符? (您可以通过发出另一个打印命令来检查)。
Eclipse 在控制台输入上总是很奇怪。如果它以某种方式在字符串中保留 CR 或 LF (或两者),我不会感到惊讶,这样当您打印它们中的每一个时,您就会得到换行符。但是你应该在单词之后再换行。
That's very strange.
Are you getting an extra newline after word? (you can check by issuing another print command).
Eclipse is always weird on console input. I would not be surprised if somehow it keeps a CR or a LF (or both) in the string, so that when you print each of them, you would get a line break. But then you should get another line break after word.