I would like to parse a generated .ini file containing some config parameters, but I am a little uncertain of the format used. I am not able to change the format of the generated .ini file. This is a snippet of what the format looks like:
[Sensors]
Sensors = {
(
[0]={
SensorType=Camera
Refresh=30
}
)}
I am able to access the Sensors
variable with the following code:
import configparser
config = configparser.ConfigParser()
path = "my_config.ini"
config.read(path)
single_sensor = config["Sensors"]["Sensors"]
print(single_sensor)
Output:
{
(
[0]={
SensorType=Camera
Refresh=30
}
)}
The problem is that this is a string that I can not parse further the same way. Let’s say I want to access SensorType
. Then the following syntax would not work:
single_sensor = config["Sensors"]["Sensors"]["0"]["SensorType"]
So how could I go about parsing a .ini file in this format? Would I have to parse the string separately after retrieving what I can using the .ini section syntax?