views:

113

answers:

2

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?

A: 

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.

Uri
no im not getting another newline after word, just one, in debug mode the value is showing like this : a = str: name\r
srisar
+1  A: 

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:

a = raw_input("give a word: ").strip()
b = raw_input("give another word: ").strip()
c = a + " " + b

I have tested this code on PyDev for Eclipse Galileo on Windows7 and it works.

Hope this helps

inspectorG4dget
yea, thanks, first impression is the best impression, and i just swtched back to Wing IDE, hehehe
srisar
I don't like the concept of "fanboys" nor do I like it when people advocate the use of something without proper reason (as fanboys usually do). However, I have used both Eclipse+PyDev and WingIDE. I find Eclipse is better by far and I would strongly encourage you to not give up on it without giving it a fair chance.
inspectorG4dget