函数subprocess.lun中的env参数做什么?
在浏览子过程
模块文档时,我遇到了功能运行
,并且不确定其env> env
参数。这是官方文档:::
如果 env 不是
无
,它必须是定义的映射 新过程的环境变量;这些是用而不是 继承当前过程环境的默认行为。 它直接传递到popen
。
有人可以在我坚持的代码的背景下向我解释这个概念:
import subprocess as sp
foo= sp.run('bash ./foo_1/run_eval.sh foo_3.csv'.split(), env=os.environ.copy())
While going over the subprocess
module documentation, I came across the function run
and am not sure of its env
argument. Here is the definition from the official documentation:
If env is not
None
, it must be a mapping that defines the
environment variables for the new process; these are used instead of
the default behavior of inheriting the current process’ environment.
It is passed directly toPopen
.
Can someone explain this concept to me in the context of the code that I'm stuck on:
import subprocess as sp
foo= sp.run('bash ./foo_1/run_eval.sh foo_3.csv'.split(), env=os.environ.copy())
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它的目的是允许您在默认环境中覆盖元素。
换句话说,
完全等同于
您想在环境中覆盖某些东西可能有用的时候。
Its purpose is to allow you to override elements in the default environment.
In other words,
is exactly equivalent to just
It's when you want to override something in the environment that this might come in useful.