The task is as follows: if in the config.ini file and in the global variable are not the same, replace the value with the value of the global variable, if they are the same, output the message.

python script

 config = ConfigParser.RawConfigParser() version = 10 def test2(): global version config.read('config.ini') old_config = config.getint('INFO', 'version') if old_config != version: config.set('INFO', 'version', '%d') % version else: print 'not delete' return 'done' 

config.ini

 [INFO] version = 11 

with this code I get an error

 TypeError: unsupported operand type(s) for %: 'NoneType' and 'int' 

    1 answer 1

    You are either sealed, or do not understand how % works. This is a string formatting operator. You are trying to apply it to the result of the function. It should be like this:

     config.set('INFO', 'version', '%d' % version) 

    PS next time, post the full error message, otherwise you don’t really want to copy it somewhere, then run it, and so on.

    • I did not notice, thank you) - Insider