In this video I go over how to create Environment Variables, sometimes referred to as Environmental Variables and how to access these variables when programming with Python code.
Terminal Commands
export MY_COOL_VAR="mySecretValue"
Persist across sessions:
nano ~/.zshrc
Add the following line:
export MY_COOL_VAR="mySecretValue"
Exit the file by clicking control and the “X”, press Y to confirm and enter to save and exit.
Put the following command in terminal:
source ~/.zshrc
Python Code:
import os
Accessing an environment variable
my_variable = os.environ.get('MY_COOL_VAR')
Using the variable
if my_variable:
print(f"The value of MY_VARIABLE is: {my_variable}")
Auf dieser Seite können Sie das Online-Video Python: Environment Variables mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer LearnEDU 02 April 2024 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 59 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!