'Python split string having n dots and get the value from toml
I am having a toml file config.toml
path.repo_uat7="/home/developer/user1"
path.repo_uat12="/home/repo/user21"
database.hostname.uat7="dbname7"
database.hostname.uat12="dbname12"
database.port="1825"
db.cluster.nodes=["cluster1:15382","cluster2:15382"]
I am reading the above file using python code:
#!/usr/bin/env python3
import toml
import sys
data = toml.load("config.toml")
desc = str(sys.argv[1])
st = desc.split(".")
st1 = st[0]
st2 = st[1]
print(data[st1][st2])
If I want value for path.repo_uat7, I am running the code as:
python getvar.py path.repo_uat7
which is giving the required output /home/developer/user1
to get the value of db.cluster.nodes I am runnig code as
python getvar.py db.cluster.nodes
and I am getting output as: {'nodes': ['cluster1:15382', 'cluster2:15382']} I want the output to be ['cluster1:15382', 'cluster2:15382']
Is there any way to split the dot separated string, which can be used if it string is having 2 dots, 3 or n? Please help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
