Python: Environment Variables

Publié le: 02 avril 2024
sur la chaîne: LearnEDU
59
1

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}")


Sur cette page du site, vous pouvez voir la vidéo en ligne Python: Environment Variables durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur LearnEDU 02 avril 2024, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 59 fois et il a aimé 1 téléspectateurs. Bon visionnage!