are there some special about '\x1a' symbol

Mel mwilson at the-wire.com
Sat Jan 10 17:27:40 CET 2009


sim.sim wrote:

> Hi all!
> 
> 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 the End-of-file mark that Windows inherited from MS-DOS and CP/M. 
The underlying Windows libraries honour it for files opened in text mode.

open ('test', 'rb').read()

will read the whole file.

        Mel.




More information about the Python-list mailing list