1

I am puzzled over some code I wrote a while back ( yep no comments gotcha!) and it's to do with an "at" flag in with open. Does it exist because I can't find anything on it and if not is python ( I use 3.4) just ignoring the 't' part.

with open(cumulative_file ,'at') as c:
    c_csv = csv.writer(c)
    c_csv.writerows(hv_today)
awesoon
  • 32,469
  • 11
  • 74
  • 99
theakson
  • 502
  • 7
  • 23
  • Python distinguishes between binary and text I/O. Files opened in binary mode (including 'b' in the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when 't' is included in the mode argument), the contents of the file are returned as str, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given.Read https://docs.python.org/3/library/functions.html#open – Mazdak Dec 29 '15 at 10:49
  • sorry didn't see this in my search thanks for the heads up – theakson Dec 29 '15 at 11:02
  • No problem, took me a while to find it too ;) Your question is still good so people can find a question directly on the `'at'` flag as well :) – poke Dec 29 '15 at 11:21
  • you are very kind :-) in trump's America my question would be a thought crime :-) – theakson Dec 29 '15 at 12:44

3 Answers3

1

Yes, it's valid. Check the docs on the open() function:

The available modes are:

Character     Meaning
'r'   open for reading (default)
'w'   open for writing, truncating the file first
'x'   open for exclusive creation, failing if the file already exists
'a'   open for writing, appending to the end of the file if it exists
'b'   binary mode
't'   text mode (default)
'+'   open a disk file for updating (reading and writing)
'U'   universal newlines mode (deprecated)

In text mode (the default, or when 't' is included in the mode argument), the contents of the file are returned as str, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given.

Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
  • I completely lost it for some reason, thanks for not giving me a hard time and giving such a complete answer – theakson Dec 29 '15 at 11:01
0

't' is for text mode. On some OSes it makes the difference when reading or writing..

AkiRoss
  • 11,745
  • 6
  • 59
  • 86
0

No, the 't' means text mode. You can omit this as text mode is the default for opening a file.

Python docs Open

rfkortekaas
  • 6,049
  • 2
  • 27
  • 34