are there some special about '\x1a' symbol

sim.sim Maksim.Kasimov at gmail.com
Tue Jan 13 06:12:08 EST 2009


On 12 янв, 16:00, John Machin <sjmac... at lexicon.net> wrote:
> 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

Ah John, thank you for your explanations!
My first impression was that your comments does not relates to my
question,
but I've found new things where I used to think there was nothing.

Now it is interesting to me how one have to give reasons to use open
(.., 'r') instead of open(.., 'rb')?
There is confusing situation when we use open(.., 'r'), are there some
scenario when we might be confused when we'll use open(.., 'rb')?

--
Maksim



More information about the Python-list mailing list