Opening the file without a mode defaults to opening it in readonly mode. If you want to write to it while reading, you’ve to specify the mode as r+
.
with open(r'G:\Programs\abc.txt', mode="r+") as khand:
...
w+
will also open the file in r/w mode, however, it wipes the contents clean.
You also use the a+
mode which will append to the end of the file, while still letting you read from it.
2
solved UnsupportedOperation: not writable python