简体   繁体   English

在C Shell脚本创建的Python中访问环境变量

[英]Accessing environment variables in Python created by C shell script

I have some hard time to access environment variables in a Python script but those environment variables are created by a C shell script. 我很难访问Python脚本中的环境变量,但是这些环境变量是由C Shell脚本创建的。 To further elaborate my question, this is what I am doing: 为了进一步阐述我的问题,这是我在做什么:

call.subprocess(['csh_script_that_sets_envar_abc.csh'])

print os.environ.get("abc")

Result: 结果:

None

Why can't the C shell script set the environment in the Python script. 为什么C Shell脚本无法在Python脚本中设置环境。

Succinctly, there isn't a reasonable way for a child process (the C shell script) to set the environment variable in the parent process (the Python code). 简而言之,子进程(C Shell脚本)没有合理的方法在父进程(Python代码)中设置环境变量。 Child processes cannot affect the parent like that. 子进程不能像这样影响父进程。

It isn't peculiar to Python or C shell per se; 它本身并不是Python或C Shell所特有的; it is a property of parent and child processes on Unix-like systems. 它是类Unix系统上父进程和子进程的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM