Skip to content
Advertisement

Python how to read() and convert to __int__

I have a text file that contains the XP of the player in it. Every time the game starts:

JavaScript

, so that the XP of the player sets to the only item in the file. And at the end of the file (around pygame.quit()) it has this code:

JavaScript

But whenever I try to do XP += (some number) in my code, I get an error saying that XP is a string (because what I .read() is always a string) so I cannot use += with a number. Is there a way to explicitly convert what you .read() to __int__?

Advertisement

Answer

Try following code

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement