0

Python error when changing an integer that is string to int type!

Hello! I was coding a database system and put a number say 10000 without any other characters inside a file. Then when I opened it inside code and tried to change it into integer, it give error! Same thing happened with tkinter.

name = input("What is the name of the item? > ")
model = input("What is the model of the item? > ")
cob = input("How much buying it cost? > ")
db.inventory(name, model, cob)
overall_read = open("overall", "r")
overall_write = open("overall", "w")
overall_read_read = overall_read.read()
overall_new_int = int(overall_read_read)
cob_int = int(cob)
overall_new = overall_new_int - cob_int
overall_write.write(str(overall_new))
main()

It should change into integer with value of 10000!

  • It appears is receiving an empty string `''` – Dani Mesejo Jan 10 '19 at 13:32
  • Have you tried using debugger of IDLE ? I will suggest read this [answer](https://stackoverflow.com/questions/6246878/how-do-you-add-breakpoints-to-a-python-program-in-idle) – manjy Jan 10 '19 at 13:35
  • It might have to do something with leading/trailing whitespace, which means you would have to use `strip()` on the string. But without knowing exactly what is being read, it's impossible to know. – Calvin Godfrey Jan 10 '19 at 13:40

0 Answers0