0

I am using Windows 10 as my os, and I went to the control panel and set two environment variables equal to an email and a password. I pressed ok and went to Sublime text and set two variables equal to the environment variables but when I ran it, it says None. I don't know how to fix this because I made sure the variables are there and restarted everything but it still says none. Here is the code.

import os

db_user = os.environ.get('EMAIL_USER')
db_pass = os.environ.get('EMAIL_PASS')

print(db_user)
print(db_pass) 

Does anyone know what the problem is?

Edit: I followed the answers and when I did them the error said, SyntaxError: cannot assign to function call And I did the DEBUSSY one and the error I had was, SyntaxError: cannot assign to function call When it said that I had a syntax error, it said it was the HOME and I checked over but it still said syntax error

Ghostly S
  • 13
  • 2
  • Does this answer your question? [How to read set environment variable in python](https://stackoverflow.com/questions/31211074/how-to-read-set-environment-variable-in-python). Take a look on its accepted comment. – Joona Yoon Oct 08 '20 at 04:23
  • Does this answer your question? [How to set environment variables in Python?](https://stackoverflow.com/questions/5971312/how-to-set-environment-variables-in-python) – Jorge Morgado Oct 08 '20 at 04:35

1 Answers1

0

If your aim is to get the path of the home directory as argument, you can just make your user send it by making shell evaluate the argument before calling the script.

I have a simple script like -

import sys
print(sys.argv[1])

In Windows I call it as -

set HOME=D:\
python script.py %HOME%

The output I get is -

D:\

In Linux -

$ python hello.py $HOME
output -

/home/random/

If you want to get it from the environment variable, and you want to pass the environment variable to use as the first argument to the script, then you should change your script like -

sys.argv[1] = os.environ.get(sys.argv[1],sys.argv[1])
Ghostly S
  • 13
  • 2
Rahman Haroon
  • 1,088
  • 2
  • 12
  • 36