Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write an ini file with if conditions

I want to write an ini file with if else conditions that i parse it with ConfigParser in python.

How to use if and Else statements in ini File ??

like image 930
chandra kanth Chandra Avatar asked Dec 04 '25 22:12

chandra kanth Chandra


1 Answers

If I understand what you're asking...

What you're probably looking to do is something like this:

Set the value of the conditions in the INI file...

[section_1]
condition_a = true
condition_b = false
condition_c = false

Read in the conditions' boolean values using getboolean()...

import ConfigParser
config = ConfigParser()
config.read('my_file.ini')

if config.getboolean('section_1', 'condition_a'):
    # Run your first conditional code
if config.getboolean('section_1', 'condition_b'):
    # Run your second conditional code
if config.getboolean('section_1', 'condition_c'):
    # Run your third conditional code
like image 58
Hill Avatar answered Dec 06 '25 14:12

Hill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!