Documentation? file/open with tea

E

Eric Pederson

WryPyY's-

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')

[to be clear, I am talking about 't' tea, not '+' plus]

Is this merely another shorthand for a binary mode, or is there more going on with 't'?

Also, is this still a valid mode going forward, or has it been deprecated?


TIA


'\xa0.ac \xa0|\n\xa0.ad \xa0|\n\xa0.ae \xa0|\n\xa0.aero \xa0|\n\xa0.af \xa0|\n\xa0.ag \xa0|\n\xa0.ai \xa0|\n\xa0.al \xa0|\n\xa0.am \xa0|\n\xa0.an \xa0|\n\xa0.ao \xa0|\n\xa0.aq \xa0|\n\xa0.ar \xa0|
[... etc.]


Eric
:::::::::::::::::::::::::::::::::::
domainNot="@something.com"
domainIs=domainNot.replace("s","z")
ePrefix="".join([chr(ord(x)+1) for x in "do"])
mailMeAt=ePrefix+domainIs
:::::::::::::::::::::::::::::::::::
 
T

Thomas D'Tak

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/d...y/en-us/vclib/html/_crt_fopen.2c_._wfopen.asp

HTH, Th.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,145
Latest member
web3PRAgeency
Top