On Fri, Oct 8, 2010 at 3:52 PM, <aurfal...@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.
>

Is the input file formatted the same way?  I would guess that the readline
call is reading the input file as one continuous line, so that the loop body
only runs once, and the '\r\n' only gets added to the very end of the file.

The simplest way to deal with this type of issue is to convert the file line
endings as needed using dos2unix and unix2dos.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to