0

I have a pretty strange problem with int() Sometimes, even if it's really just numbers, I'm getting the error

"[...] In line 2: Invalid literal with Base 10: '' "

But the value is just a number (0) It's so strange... The following code causes this error:

count = open('count.dat', 'r')
cint = int(count.read)
cint = cint + 1
count.close()
del(count)
countw = open('count.dat', 'w+')
countw.write = str(cint)
countw.close()
del(countw)

PS: I'm a newbie

dstrants
  • 7,423
  • 2
  • 19
  • 27
M-Try
  • 1
  • 3

1 Answers1

1

I thnk your code cint = int(count.read) , countw.write = str(cint) these lines should change

count = open('count.dat', 'r')
cint = int(count.read()) # as this 
cint = cint + 1
count.close()
del(count)

countw = open('count.dat', 'w')
countw.write(str(cint)) #as this
countw.close()
del(countw)

then it will work fine

before run the code

enter image description here

After running enter image description here

if you count.dat file is blank obviously it will give the error int() with base 10: ''