Removing newlines from string on windows (without replacing)

Aahz aahz at pythoncraft.com
Sun Jul 26 13:56:54 EDT 2009


In article <mailman.3714.1248551656.8015.python-list at python.org>,
Tom  <tom.sully at gmx.com> wrote:
>
>I have an annoying problem. While I mainly use Linux when I distribute
>this program to friends and on the internet, it'll get used on Windows.
>So, I tested my python program on my Windows Vista dual boot, running
>the same version of python (2.6) as my Linux, and got an error at the
>following code.
>
>s = sauce.replace("\n", "")
>
>Sauce is a string, read from a file, that I need to remove newlines
>from. This code works fine in Linux, but not in Windows. rstrip("\n")
>won't work for me, so anybody know how to get this working on Windows?

Use open(fname, 'U')
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"At Resolver we've found it useful to short-circuit any doubt and just        
refer to comments in code as 'lies'. :-)"
--Michael Foord paraphrases Christian Muirhead on python-dev, 2009-03-22



More information about the Python-list mailing list