How do you get line breaks using raw_input ? But, as soon as you have a string with some characters in it, you want to get rid, just replace them.
>>> mystr = raw_input('please enter string: ') please enter string: hello world, how do i enter line breaks? >>> # pressing enter didn't work... ... >>> mystr 'hello world, how do i enter line breaks?' >>> mystr.replace(' ', '') 'helloworld,howdoienterlinebreaks?' >>>
In the above example, I replaced all the spaces. Line '\n' represents newline characters. And \r represents the carriage return (if you are in windows, you can get them, and the second replace will handle them for you!).
mostly
# you probably want to use a space ' ' to replace `\n` mystring = mystring.replace('\n', ' ').replace('\r', '')
Note also that it is a bad idea to call your string variable, as this obscures the string module. Another name I would avoid but would like to use sometimes: file . For the same reason.
Daren Thomas May 15 '13 at 13:28 2013-05-15 13:28
source share