[Python-Dev] RE: Python on Windows chapter.

Guido van Rossum guido@CNRI.Reston.VA.US
Wed, 14 Jul 1999 08:24:53 -0400


> I asked Guido to provide comments on one of the chapters in our book:
> 
> I was discussing appending the mode ("t" or "b") to the open() call
> 
> > p.10, bottom: text mode is the default -- I've never seen the 't'
> > option described!  (So even if it exists, better be silent about it.)
> > You need to append 'b' to get binary mode instead.

In addition, 't' probably isn't even supported on many Unix systems!

> This brings up an interesting issue.
> 
> MSVC exposes a global variable that contains the default mode - ie, you can
> change the default to binary. (_fmode for those with the docs)

The best thing to do with this variable is to ignore it.  In large
programs like Python that link together pieces of code that never ever
heard about each other, making global changes to the semantics of
standard library functions is a bad thing.  Code that sets it or
requires you to set it is broken.

> This has some implications and questions:
> * Will Guido ever bow to pressure (when it arrives :) to expose this via
> the "msvcrt" module?  I can imagine where it may be useful in a limited
> context.  A reasonable argument would be that, like _setmode and other MS
> specific stuff, if it exists it should be exposed.

No.  (And I've never bought that argument before -- I always use "is
there sufficient need and no other way.")

> * But even if not, due to the shared CRTL, in COM and other worlds we
> really cant predict what the default is.  Although Python does not touch
> it, that does not stop someone else touching it.  A web-server built using
> MSVC on Windows may use it?

But would be stupid for it to do so, and I would argue that the web
server was broken.  Since they should know better than this, I doubt
they do this (this option is more likely to be used in small,
self-contained programs).  Until you find a concrete example, let's
ignore the possibility.

> Thus, it appears that to be 100% sure what mode you are using, you should
> not rely on the default, but should _always_ use "b" or "t" on the file
> mode.

Stop losing sleep over it.

> Any thoughts or comments?  The case for abandoning the CRTL's text mode
> gets stronger and stronger!

OK, you write the code :-)

--Guido van Rossum (home page: http://www.python.org/~guido/)