\r\n or \n notepad editor end line ???

Bill Mill bill.mill at gmail.com
Wed Jun 8 09:36:45 EDT 2005


On 8 Jun 2005 06:24:05 -0700, ajikoe at gmail.com <ajikoe at gmail.com> wrote:
> Hello,
> 
> I use windows notepad editor to write text.
> 
> For example I write (in d:\myfile.txt):
> Helo
> World
> 
> If I open it with python:
>   FName = open(d:\myfile.txt,'r')
>   h = FName.readlines()
>   print h
> 
> I get h : ['Helo\n', 'World']
> 
> I thought notepad use \r\n to to end the line.
> 
> What's wrong with it?

On windows, opening a file without 'b' in the file type argument does
some things you might not expect, including changing /r/n to /n. Try:

>>> f = file('d:/deleteme.txt', 'rb')
>>> f.read()
'testing\r\n1\r\n2\r\n3'
>>> f = file('d:/deleteme.txt', 'r')
>>> f.read()
'testing\n1\n2\n3'

Peace
Bill Mill
bill.mill at gmail.com



More information about the Python-list mailing list