Categories
Python Answers

How to set environment variables in Python?

Spread the love

Sometimes, we want to set environment variables in Python.

In this article, we’ll look at how to set environment variables in Python.

How to set environment variables in Python?

To set environment variables in Python, we can put the variable os.environ dict.

For instance, we write

os.environ["FOO"] = "1"

to set the FOO environment variable to '1‘.

We can get the environment variable’s value with

print(os.environ["DEBUSSY"])

Conclusion

To set environment variables in Python, we can put the variable os.environ dict.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *