3

I have problem with raw_input command. I use it in program and run the program in cmd. Then it asks input but when I paste there text which has empty lines in it, then python takes it automatically as enter command. I want it to understand that it's not enter command but just new line. How could I do this?

2
  • 2
    It's hard to understand exactly what's causing your problem without seeing a bit of code. Can you include a short program (10 lines or so) that reproduces the problem? Commented Dec 8, 2013 at 15:25
  • First search gave me this: how-to-process-raw-data-in-python Commented Dec 8, 2013 at 15:34

2 Answers 2

2

To do that, you can't use raw_input function, because this function finish reading input after first new line character. Instead you can use sys.stdin:

>>>import sys
>>>input = sys.stdin.read()
hi
this text has
new lines
Ctrl^D
>>>print input
hi
this text has
new lines

To finish reading input you'll have to send EOF char, which in Linux is Ctrl+D and in Windows is Ctrl+Z

Hope this helps!

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

Comments

1

as per python documentation, raw_input() is designed to have \n as the key that ends the input, and it has not been designed for another way of interacting.

If you want to use another way of using the input you can try using fileinput() or sys.stdin.read() and iterate over the lines or the characters and create the behavior you're looking for.

Have a look at the answers of questions such as that one

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.