Newbie: easy filecopy?

Gordon McMillan gmcm at hypernet.com
Wed Jun 16 00:38:32 EDT 1999


Holger Jannsen writes:

> Another ascpect to my question of yesterday:
> 
> The problem with 
> f=open(aFile)
> x=f.read()
> f.close
> f.open(toFile)
> f.write(x)
> f.close
> is, that some special ASCII-codes are not copied as usual 
> under Windows-systems, so e.g. CarriageReturn (tested with normal
> Asccii-text).

You're doing something funny, but not sure what from your pseudo 
code.

open(aFile) is equivalent to open(aFile, 'r'), which is text mode 
- it will translate \r\n to \n on input. open(toFile,'w') would also 
open text mode, and translate \n to \r\n on ouput. Your symptoms 
match reading from a file in text mode, but writing in binary mode 
(eg, open(toFile, 'wb')).

Don't worry - you're in good company. Netscape gets them confused 
frequently too.

- Gordon




More information about the Python-list mailing list