You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to include environment variables in the config.ini file. I often find myself adding a bunch of long filepaths or complicated variables that might change in the future, so this would be really convenient for me.
I already have an idea of how you could accomplish this. Basically, you could just subclass BasicInterpolation and just expand the variables before the value is accessed:
import configparser, os
class EnvInterpolation(configparser.BasicInterpolation):
def before_get(self, parser, section, option, value, defaults):
return os.path.expandvars(value)
And then you would just initialize the config parser as:
You could even subclass ExtendedInterpolation if you want the user to access variables from other sections (although the interpolation syntax is a bit different). I would really appreciate if you did this.
The text was updated successfully, but these errors were encountered:
I would like to include environment variables in the config.ini file. I often find myself adding a bunch of long filepaths or complicated variables that might change in the future, so this would be really convenient for me.
For example:
I already have an idea of how you could accomplish this. Basically, you could just subclass BasicInterpolation and just expand the variables before the value is accessed:
And then you would just initialize the config parser as:
parser = configparser.ConfigParser(interpolation=EnvInterpolation())
You could even subclass ExtendedInterpolation if you want the user to access variables from other sections (although the interpolation syntax is a bit different). I would really appreciate if you did this.
The text was updated successfully, but these errors were encountered: