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}")
In questa pagina del sito puoi guardare il video online Python: Environment Variables della durata di ore minuti seconda in buona qualità , che l'utente ha caricato LearnEDU 02 aprile 2024, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 59 volte e gli è piaciuto 1 spettatori. Buona visione!