将环境变量注入字符串路径

2024-09-30 01:28:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下字符串:

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有关


Tags: 函数字符串envstringosenviron环境变量location

热门问题