I stumbled across an issue of file handling, second line gives you an value of 9 for no reason, third line gives an Error io.UnsupportedOperation: not readable
c = open("Test.txt", "w+")
c.write("Hey there")
content = c.read()
c.close
print (content)
How can I solve this ?
That is the return value from the
write()
function in Python 3. The value is the number of characters written to the file.Not sure what you've done here. Following the
write()
, the file pointer is positioned at the end of the file. If you really opened the file withw+
then you should not see an error, but 0 characters should be read from the file. If you opened the file with modew
, then you would get theio.UnsupportedOperation
exception because the file is not opened for reading. Check which mode you used when you tested.Try this:
Output: