0

I want to have a .ini entry that references special variables e.g.

[magic_module]
magic_directory: ${env:PWD}/magic

currently, I have the non-portable

[magic_module]
magic_directory: C:/Users/user1/projects/project1/magic

I would like to have a .ini path entry that is more portable instead of hard-coded to my computer. Does the Python ConfigParser natively perform substitutions like this?


This is slightly different than SO question ConfigParser and String interpolation with env variable because I am wondering about any possible default interpolated variables, not just environment variables.

This is for passing information to a different module (mypy) that uses ConfigParser.

Specifically, this is for improving portability in a Python package. I'm trying to set the mypy_path within a mypy.ini while working with a pipenv-created virtualenv python environment. The user install module paths will change so I want to portably set that for mypy.

Using Python 3.7.

JamesThomasMoon
  • 6,169
  • 7
  • 37
  • 63
  • Possible duplicate of [ConfigParser and String interpolation with env variable](https://stackoverflow.com/questions/26586801/configparser-and-string-interpolation-with-env-variable) – CryptoFool Feb 24 '19 at 06:06
  • 1
    Maybe I am misunderstand something in my experience I found that: a) `.env`-files + `pipenv run` + `os.environ` or b) `.env`-files + [python-dotenv](https://github.com/theskumar/python-dotenv) solves all my needs. Both solutions are quite portable. Do I miss something? – Alex Yu Feb 25 '19 at 03:00

0 Answers0