I have the following dictionary:
config = {
'base_dir': Path(__file__).resolve(strict=True).parent.absolute(),
'app_dir': '<base_dir>/app'
}
I want to replace <base_dir>
with the value of <base_dir>
so I did this:
for key, value in config.items():
if type(value) == str:
vars_to_replace = re.findall(r'\<.+\>',value)
for var in vars_to_replace:
config[key] = value.replace(var,config[var[1:-1]])
Currently getting the error: TypeError: replace() argument 2 must be str, not WindowsPath
If I wrap my config[var[1:-1]]
with str()
. It gets rid of the error but I lose the WindowsPath and now app_dir becomes a string. I want to reserve the object as WindowsPath.