How do I check environment variables for my specific user in windows 10?

Viewed 182

I did a few google searches on how to use environment variables in python. When I try to use os.environ.get('token') I get None returned. I can only assume it's because 'token' is in my user variables and not my system ones. I don't have admin permissions on my machine. How would I fix this/use environment variables for my user? Variables: (ignore the french) my user variables

2 Answers

Have you set this variable after you have started your python terminal. Have you tried restarting your python terminal I have tried setting local variable in my windows OS, the starting a python terminal and can access the local variable fine

enter image description here

The documentation for os.environ mentions this...... https://docs.python.org/3/library/os.html#os.environ

A mapping object representing the string environment. For example, environ['HOME'] is the pathname of your home directory (on some platforms), and is equivalent to getenv("HOME") in C.

This mapping is captured the first time the os module is imported, typically during Python startup as part of processing site.py. Changes to the environment made after this time are not reflected in os.environ, except for changes made by modifying os.environ directly.

So any changes to variables made outside of your code will not be reflected in your os.environ mapping.

Try following the instructions here using the python-decouple package.

They also explain there why you get None

Related