Рет қаралды 43
#python #pythonforbeginners #vscode
How to Create or Modify Environment Variables in Windows
1. setx MY_VAR "Hello World"
2. echo %MY_VAR% - displays the value of the variable. Close and reopen the command prompt.
3. set - displays all variables.
4. setx MY_VAR “” unset a variable.
5. set TEMP_VAR=Temp_Value - variables will not persist after the command prompt is closed.
Below is the code I used in the video:
import requests
import os
#set url=official-joke-...
Get the 'url' environment variable
url = os.getenv('url')
Make the GET request if 'url' is set
if url:
response = requests.get(url)
joke = response.json()
print(f"Joke: {joke['setup']}")
print(f"Punchline: {joke['punchline']}")
else:
print("Environment variable 'url' is not set.")