简体   繁体   中英

Change the command line variable value in python

In command line Ubuntu LTS16.04, I have:

IMAGE_FILE="a/b/c"

I want to change the value of this variable with python statements. What I have to do? For instance, I want the variable to be set to null "".

I used os.environ, however after exiting python exit (). Run echo $ IMAGE_FILE is still the old value

Thank you for reading the question!

What you ask for cannot be done the way you want it to. The problem is that Python starts as a subprocess of your shell, and a subprocess is not allowed to modify the environmental variable of its parent.

When the subprocess starts, it inherits the environment of its parent and all changes done will be visible in the subprocess, and in further processes spawned by the first subprocess. But, when it exists, the environment of the parent will still remain as before the first subprocess creation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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