🌳 Environment Variable
- Solo, at your own pace
🎯 Learning Objective
- Use environment variables in PowerShell and Python.
📜 Instructions
Step 1
Write a Python script that saves environment variables
to a JSON file. You can use the os module to access
environment variables.
Step 2
- Run the Python script you wrote in Step 1 in PowerShell.
- Make a copy of the generated JSON file.
- Add an environment variable in PowerShell and rerun the Python script.
- Verify that the environment variable has been added to the JSON file.
Step 3
Modify your script to read the environment variable MYAPP_MODE
which will be either dev or prod. Depending on the value of this variable,
the script should display a different message in the console.
Step 4
Test your script by setting the environment variable MYAPP_MODE to
dev and running it. Then change the variable to prod and run the script again.
Ensure that the displayed message corresponds to the variable's value.