1

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?

srisar
  • 1,495
  • 5
  • 18
  • 27
  • Yo, result is name, bro! Word! – Thomas Mar 27 '10 at 18:23
  • what?, i didnt understand what youre saying – srisar Mar 27 '10 at 18:25
  • Never mind that. You could/should use `raw_input` instead of `input`. It's less scary because it doesn't do an `eval`. – Thomas Mar 27 '10 at 18:25
  • 1
    @Thomas: In Python-3.x, `input` acts as `raw_input` does for Python-2.x. (`raw_input` was renamed `input`). – unutbu Mar 27 '10 at 18:27
  • im afraid that python 3.1 doesnt have a function called "raw_input" – srisar Mar 27 '10 at 18:27
  • You didn't say 3.1. Anyway, could you try printing the values of `repr(a)`, `repr(b)` and `repr(c)`? Maybe a `\r` or `\n` snuck in there. – Thomas Mar 27 '10 at 18:31
  • now you can, but thanks the method you specify here did worked for me, despite the fact that the information was wrong but the function rstrip() is a good one. thanks unutbu – srisar Mar 27 '10 at 18:43

2 Answers2

1

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
  • 110,290
  • 27
  • 149
  • 241
  • yea, thanks, first impression is the best impression, and i just swtched back to Wing IDE, hehehe – srisar Mar 29 '10 at 11:36
  • 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 Mar 29 '10 at 22:40
0

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
  • 88,451
  • 51
  • 221
  • 321
  • no im not getting another newline after word, just one, in debug mode the value is showing like this : a = str: name\r – srisar Mar 27 '10 at 18:31