script in Linux vs Windows
MRAB
python at mrabarnett.plus.com
Fri Oct 8 19:41:14 EDT 2010
On 08/10/2010 22:52, aurfalien at gmail.com wrote:
> Hi all,
>
> Unsure how to deal with what appears to be \n vs \r issues.
>
> The following code works in Linux;
>
> o = open("axenfs.reg")
> n = open("axenfs2.reg", "a")
> while 1:
> line = o.readline()
> if not line: break
> line = line.replace("dword:00000","dword:0000044e")
> n.write(line)
> n.close()
>
> But in Windows, its one continues line with a bunch of squares in it.
>
> So I add + '\r\n' to my second to last line so it looks like;
>
> n.write(line + '\r\n')
>
> But I still get one continuous line with squares in it.
>
> Any ideas? I've been googing all day to no avail.
>
> Desperately seeking advice.
>
Open the input file in binary mode and print out the repr for a few
lines to see what the file encoding and line ending actually is. That
always helps me. :-)
More information about the Python-list
mailing list