Documentation? file/open with tea

Tim Peters tim.peters at
Mon Sep 20 07:19:14 CEST 2004

[Daniel Dittmar]
>> And I think using 't' is a mainly a Windows thing and not portable.

[Roger Binns]
> It is actually a C standard thing and is *very* portable.

There are three phenomena getting confused here.

1. The difference between text and binary mode is standard C, although
   it doesn't actually exist on all platforms.  Which is fine by the C standard.
   A platform is allowed, but not required, to treat text mode and binary
   mode differently.

2. The "t" mode flag to open() is not standard C, it's a Microsoft extension
   to C.

3. Nevertheless, nearly all platform C implementations ignore mode
   flags to open() that they don't recognize.  So it's quite likely that
   that a non-Windows box will *accept* a mode argument to open()
   containing "t", but will ignore the "t" part.  For example, here on a
   FreeBSD box:

>>> open("a", "wkqrbt")
<open file 'a', mode 'wkqrbt' at 0x817cb20>

God only knows what the C library did there, but it *probably* ignored
everything at and after the first mode letter it didn't recognize

Don't use "t" if you want to be clear.  Text mode is the default, and
standard C doesn't offer any way to explicitly request that default. 
Microsoft supports "t" because it's *possible* to force MS's C runtime
into using binary mode by default; I've never seen that done in real
life, but, if someone does it, then it's necessary (although not
standard C) to use "t" if you want to open a file in text mode.

More information about the Python-list mailing list