我有以下字符串:
some_string = "%envvar1%\location\execution.exe"
envvar1是一个值为“c:\”的环境变量,我想要一些如下函数:
some_string = "%envvar1%\location\execution.exe"
inject_env_variable(some_string)
print(some_string)
"c:\location\execution.exe"
使用正则表达式和os.environ创建这样的函数并不困难,但我想知道是否有某种内置模块处理这类事情
注意:google搜索任何带有“path”和“python”的单词都非常乏味,因为所有的搜索都与pythonpath:p有关
os.path.expandvars
可能就是你想要的https://docs.python.org/3/library/os.path.html#os.path.expandvars我应该做的
相关问题 更多 >
编程相关推荐