Bird
0
0

How can you set an environment variable 'MODE' to 'production' within a Python script so that subprocesses inherit it?

hard📝 Application Q9 of 15
Python - Standard Library Usage
How can you set an environment variable 'MODE' to 'production' within a Python script so that subprocesses inherit it?
Aos.environ['MODE'] = 'production'
BBoth A and B
Cos.setenv('MODE', 'production')
Dos.putenv('MODE', 'production')
Step-by-Step Solution
Solution:
  1. Step 1: Understand environment variable setting methods

    os.environ['MODE'] = 'production' sets the variable in Python's environment dictionary. os.putenv('MODE', 'production') sets it at OS level. Both affect subprocesses.
  2. Step 2: Check for invalid methods

    os.setenv does not exist in Python standard library.
  3. Final Answer:

    Both A and B -> Option B
  4. Quick Check:

    Set env var in Python = os.environ or os.putenv [OK]
Quick Trick: Use os.environ or os.putenv to set env vars in Python [OK]
Common Mistakes:
  • Using non-existent os.setenv
  • Thinking only one method works

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes