are there some special about '\x1a' symbol

John Machin sjmachin at lexicon.net
Mon Jan 12 09:00:16 EST 2009


On Jan 13, 12:45 am, "sim.sim" <Maksim.Kasi... at gmail.com> wrote:
> On 10 ÑÎ×, 23:40, John Machin <sjmac... at lexicon.net> wrote:
>
>
>
>
>
> > On Jan 11, 2:45šam, "sim.sim" <Maksim.Kasi... at gmail.com> 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?
>
> > You've already got two good answers, but this might add a little more
> > explanation:
>
> > You will aware that in Windows Command Prompt, to exit the interactive
> > mode of Python (among others), you need to type Ctrl-Z ...
>
> > | C:\junk>python
> > | Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
> > (Intel)] on
> > win32
> > | Type "help", "copyright", "credits" or "license" for more
> > information.
> > | >>> problem = '\x1a'
> > | >>> ord(problem)
> > | 26
> > | >>> # What is the 26th letter of the English/ASCII alphabet?
> > | ...
> > | >>> ^Z
> > |
> > | C:\junk>
>
> > HTH,
> > John
>
> Hi John,
>
> I agree - those two answers are really good. Thanks to Mel and Marc.
> I'm sorry if my stupid question was annoyed you.

I didn't think your question was stupid. Stupid was (a) CP/M recording
file size as number of 128-byte sectors, forcing the use of an in-band
EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF
decades after people stopped writing Ctrl-Z at the end of text files.

And I wasn't annoyed either ... I was merely adding the information
that Ctrl-Z and '\x1a' were the same thing; many people don't make the
connection.

Cheers,
John



More information about the Python-list mailing list