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?

7
  • Yo, result is name, bro! Word! Commented Mar 27, 2010 at 18:23
  • what?, i didnt understand what youre saying Commented Mar 27, 2010 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. Commented Mar 27, 2010 at 18:25
  • 1
    @Thomas: In Python-3.x, input acts as raw_input does for Python-2.x. (raw_input was renamed input). Commented Mar 27, 2010 at 18:27
  • im afraid that python 3.1 doesnt have a function called "raw_input" Commented Mar 27, 2010 at 18:27

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

yea, thanks, first impression is the best impression, and i just swtched back to Wing IDE, hehehe
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.
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.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.