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}")
En esta página del sitio puede ver el video en línea Python: Environment Variables de Duración hora minuto segunda en buena calidad , que subió el usuario LearnEDU 02 abril 2024, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 59 veces y le gustó 1 a los espectadores. Disfruta viendo!