f.write(chr(10)) ?

Drew Csillag drew.csillag at starmedia.net
Mon Jul 24 20:15:36 EDT 2000


On Mon, Jul 24, 2000 at 06:32:05PM +0000, ingo wrote:
> Hi all,
> I'm just beginning with programming and Python. 
> Writing a file using this:
> 
> >>> f=open("testpy",'wd')
> 
> >>> f.write(chr(10)) 	
> 
> >>> f.close()
> 
> When I open the file with HexEdit I see:
>     	0000: 0D 0A
> I expected 
>     	0000: 0A
> 
> What's wrong?

Try instead:
f=open("testpy", 'wb') # note wb not wd

This opens the file in binary mode instead of the default ascii mode, which
does line ending conversions (i.e. LF -> CRLF).

Cheers,
Drew
-- 
print'e=%s'%(lambda x:'%s.%s'%(x[0],x[1:-1]))(str(reduce(lambda
(a,b),y,z=10L**1835:(a+z/b,b*y),[[0L,1L]]+range(1,752))[0]))

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 248 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20000724/d3267701/attachment.sig>


More information about the Python-list mailing list