I use Windows 7.
myfile = open("matedata.txt", "a+")
print myfile.readline()
myfile.write("1")
myfile.close()
And this doesn't work.
myfile.write("1")
IOError: [Errno 0] Error
When you open a file with python, you need to specify the type of access you want (read, write or append):
the '+' means update/create new if doesn't exists.
you getting IOError because you open file and you try to do both reading and writing with the same FD(file discreptor)
+ does not mean to create a file, but instead it means to open a file for both reading and writing.
withstatement to handle your open file, rather than explicitly closing it.a+mode, and did a read operation before a write operation. This makes windows unhappy for whatever reason. I remember there being a workaround if you really need to do this, but really just don't read and write ina+mode.