Home > AI > Language > Python >

python operate a file

my_data_file = open('data.txt', 'w')
  • r – (default mode) open the file for reading
  • w – open the file for writing, overwriting the content if the file already exists with data
  • x – creates a new file, failing if it exists
  • a – open the file for writing, appending new data at the end of the file’s contents if it already exists
  • b – write binary data to files instead of the default text data
  • + – allow reading and writing to a mode

Leave a Reply