Everyone, hello!
I'm not able to count properly, and I'm at a loss. A second pair of eyes would really be helpful.
I'm getting a variable from my config file as:
import ConfigParser
config = ConfigParser.ConfigParser()
config.read("config.ini")
count1 = config.get('Counter','count1')
>>> print count1
5
However, when I want to simply substract - 1 from this variable, as so:
count1 = (count1 - 1)
I'm confronted with an error:
TypeError: unsupported operand type(s) for -: 'str' and 'int'
Any help would be really appreciated. Thanks!
You can't do arithmetic with strings, you have to convert it first to an integer with the int function:
count1 = int(config.get('Counter', 'count1'))
You could also use the config.getint or config.getfloat methods.
If you need a float, you can use the float function instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With