python - How to get configuration file path with configparser object -


the code below initiates conf variable instance of configuration class inherits configparser. in __init__ method reads config_file , stores configuration context in memory. how can file path config_file having conf object?

import configparser import os    class configuration(configparser.configparser):     def __init__(self, config_file):         configparser.configparser.__init__(self)          self.read(config_file)      def savesettings(self):         if not self.has_section('section a'):             self.add_section('section a')         self.set('section a', 'option 1', 'value 1')  config_file = os.path.join(os.path.expanduser('~'),'config.ini' ) conf = configuration(config_file) conf.savesettings() 

simply assign information instance (self):

def __init__(self, config_path):     configparser.configparser.__init__(self)      self.read(config_path)     self.config_path = config_path # instance attribute 

then can access object:

conf_path = os.path.join(os.path.expanduser('~'),'config.ini' ) conf = configuration(conf_path)  print( conf.conf_path ) # access via object 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -