Dictionary iterates keys by default
Basic File Usage
with open(file_name, [access_mode]) as f:
file_name
: a string valueaccess_mode
: determines the mode in which the file has to be opened, i.e., read, write, append, etc.
f
methods
f.write(data)
: writes the string to the file, needs'\n'
if writing multiple lines
access modes
w
: overwrites the filea
: appends data to the end of the filer
: read-only file access
Ways to read a file
with open('myfile.txt', 'r') as f:
print(f.read())
for line in f.readlines():\n\tprint(line)
for line in f:\n\tprint(line)