are there some special about '\x1a' symbol

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sat Jan 10 17:08:35 CET 2009


On Sat, 10 Jan 2009 07:45:53 -0800, sim.sim wrote:

> I had touch with some different python behavior: I was tried to write
> into a file a string with the '\x1a' symbol, and for FreeBSD system, it
> gives expected result:
> 
>>>> open("test", "w").write('before\x1aafter') open('test').read()
> 'before\x1aafter'
> 
> 
> but for my WinXP box, it gives some strange:
> 
>>>> open("test", "w").write('before\x1aafter') open('test').read()
> 'before'
> 
> Here I can write all symbols, but not read. I've tested it with python
> 2.6, 2.5 and 2.2 and WinXP SP2.
> 
> Why is it so and is it possible to fix it?

\x1a is treated as "end of text" character in text files by Windows.  So 
if you want all, unaltered data, open the file in binary mode ('rb' and 
'wb').

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list