Documentation? file/open with tea

Thomas D'Tak outpost at rumblefish.org
Sun Sep 19 22:42:02 CEST 2004


On Sun, 19 Sep 2004 11:40:37 -0800, Eric Pederson wrote:
 
> I've come across this file operation in others' code and have not seen any documentation for it: 
> the use of "t" in the mode of file opening, such as:
> 
> f1=open(somefile, 'at')
> f2=open(otherfile, 'rt')
> 
> Is this merely another shorthand for a binary mode, or is there more going on with 't'?

No, but for 'text' resp. 'translated' mode 
(though it comes from C/C++ on Windows).

Python's documentation on 'open()' (resp. 'file()') says, that the first
two arguments are the same as for C's stdio's 'fopen()'. And on Windows
you will often find that fopen() supports 't' as a mode extension (like
the well known 'b' for binary mode):

  'b': open file in binary (untranslated) mode

  't': open file in text (translated) mode; 
       (e.g. look for Ctrl-z as EOF marker)

Links:

Python's file() resp. open():
  http://www.python.org/doc/2.3.4/lib/built-in-funcs.html#built-in-funcs

(E.g.) Visual C++'s fopen():
  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_fopen.2c_._wfopen.asp

HTH, Th.




More information about the Python-list mailing list