September 2018
Intermediate to advanced
426 pages
10h 46m
English
The classic way of working with files is to use the open() method. This method allows you to open a file, returning an object of the file type:
open(name[, mode[, buffering]])
The opening modes of the file can be r(read), w(write), and a(append). We can add to these the b (binary), t (text), and + (open reading and writing) modes. For example, you can add a "+" to your option, which allows read/write to be done with the same object:
>>> my_file=open("file.txt","r”)
To read a file, we have several possibilities: