Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

I have a config document abc.txt which looks to some degree like: 

path1 = "D:\test1\first"

path2 = "D:\test2\second"

path3 = "D:\test2\third"

I need to peruse these ways from the abc.txt to utilize them in my program to avoid hard coding.

1 Answer

0 votes
by (26.4k points)

To use my example,Your file "abc.txt" requirements to resemble: 

[your-config]

path1 = "D:\test1\first"

path2 = "D:\test2\second"

path3 = "D:\test2\third"

At that point in your software you can utilize the config parser: 

import ConfigParser

and afterward in you code:

configParser = ConfigParser.RawConfigParser()   

 configFilePath = r'c:\abc.txt'

 configParser.read(configFilePath)

Use case:

self.path = configParser.get('your-config', 'path1')

Improve your knowledge in Python from scratch using python online courses

Related questions

0 votes
1 answer
asked Jul 13, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
asked Jul 11, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
0 votes
2 answers
...