import configparser
class ReadConfig:
"""Define a class that reads configuration files """
def __init__(self):
configpath = "absolute path to the config.ini file"
self.cf = configparser.ConfigParser()
self.cf.read(configpath)
def get_db(self, param):
value = self.cf.get("Mysql", param)
return value
if __name__ == '__main__':
test = ReadConfig()
t = test.get_db("host")
print(t)
Change configpath to absolute path
Similar Posts:
- python mac install MySQLdb ModuleNotFoundError No module named ‘ConfigParser’
- Python: How to Batch Read the Form Information in Word and output them to Excel file
- Python3 urlopen() TypeError: can’t convert ‘bytes’ object to str im…
- [Solved] Spring MVC cross server upload error: returned a response status of 405 method not allowed
- [Solved] com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes
- Python: __ new__ Method and the processing of typeerror: object() takes no parameters
- Tomcat set x-frame-option
- How to Solve Libpng warning ICCP error
- Summary of common functions of urllib.parse in Python 3
- Mysqldump error: tab (ErrCode:13-Permission denied) [How to Solve]