-2

How can I set my DATABASE_URL as an environment variable in Python on Windows?

zerecees
  • 697
  • 4
  • 13
Bell9999
  • 31
  • 1
  • 6
  • 1
    Do you have an example or a specific issue? You will be more likely to receive an answer if you post some code. Environment variables are available in the `os` module in `os.environ` – Iain Shelvington Jun 16 '20 at 04:23

1 Answers1

0

With the os module of the standard library;

>>> import os
>>> os.environ.get('NON_EXISTANT')
None
>>> os.environ.get('HOME')
/home/username

If you want to set such a variable;

>>> os.environ['YOUR_VARIABLE'] = 'your_value'

Note: print all available environment variables with os.environ.

Sy Ker
  • 2,047
  • 1
  • 4
  • 20