-4

hello and thanks

i hope i am posting in the correct area

i want to convert a .ini file into local variables. for example, let's say i have this .ini

[DEFAULT]
Value1=False
Value2=0
[section]
Value1=True

i need to create variables named

Value1 with the value of True

Value2 with the value of 0

so i could write code like

if Value1==True: DoA()
if Value2==0: DoB()

thanks so much, jojo

1 Answers1

1
import configparser

config = configparser.ConfigParser()
config.read('config.ini')

variable1 = config['section']['Value1']
variable2 = config['DEFAULT']['Value2']

if variable1 == 'True':
    doA()
if variable2 == '0':
    doB()

Note that config keys are parsed as strings. If you need one as an integer object, use it within int()

Freese
  • 177
  • 8