Bad open mode for filePYL-W1501
The mode with which the file is opened is not valid. Python supports: r
, w
, a
, and x
modes with t
and b
modifiers, for t
ext files and b
inary files respectively. The +
mode can also be used to open the file for updating (reading and writing).
Bad practice
with open('log.txt', 'rw') as logfile: # Doesn't work
text = logfile.read()
logfile.write('test log')
Recommended
with open('log.txt', 'r+') as logfile:
text = logfile.read()
logfile.write('test log')