How to handle data in a file?
- Data from an opened file can be read using any of the methods:
read
,readline
andreadlines
. - Data can be written to a file using either
write
orwritelines
method. - A file must be opened, before it is used for reading or writing.
Example: Reading a file
fp = open('temp.txt', 'r') # opening content = fp.read() # reading fp.close() # closing