I don't know what happen, but my code doesn't want to work properly. This is the code:
with open("count.txt","w+") as f:
print(f.read())
a=int(f.read())
b=int(a+1)
print(str(b))
f.write(str(b))
input()
I put the "count.txt" in same directory, and this is the content of "count.txt"
0
and this is the error that I got:
Traceback (most recent call last):
File "C:\FILEDIRECTORY\plus.py", line 3, in <module>
a=int(f.read())
ValueError: invalid literal for int() with base 10: ''
Then, the "count.txt" become blank (0 bytes). I tried to change the mode to "r", but the same error happen, but the content of "count.txt" doesn't get erased. Then I try to change the mode to "w", change the f.write content to "1", and make the other code comment.
with open("count.txt","w") as f:
'''print(f.read())
a=int(f.read())
b=int(a+1)
print(str(b))'''
f.write("1")
input()
But now it works! The "count.txt" content become "1"! I also try this :
with open("count.txt","w") as f:
'''print(f.read())
a=int(f.read())
b=int(a+1)
print(str(b))'''
a="1"
f.write(a)
input()
And it still works! So i think the read mode is broken, but i don't know why. Maybe I Install Python Incorrectly?