Eljay
Eljay

Reputation: 951

Function of os.environ in python

I am new to python.I am not having any Knowledge of Python, i came across following line of python code

os.environ.get('IS_THIS_POSSIBLE', 'FALSE') == 'TRUE'

what does os.environ.get Do? Is it accessing something particular to OS internals.

Upvotes: 4

Views: 8459

Answers (3)

flycee
flycee

Reputation: 12736

Yes, it is getting operation system's environment variables. For your code, it's returning the value of os-environment variable 'ENABLE_BONDING_ROUTER', return 'FALSE' if it does not exist.

To set an environment variable see the following post on Super User: What are PATH and other environment variables, and how can I set or use them?

Upvotes: 2

Tony Williams
Tony Williams

Reputation: 647

os.environ is a bunch of functions to read and write the system environment and os.environ.get() returns an environment variable. See this documnetation page for some details.

Upvotes: 1

jwilner
jwilner

Reputation: 6606

Most OS's have environment variables -- for example, the $PATH variable. Python runs within the OS, and sometimes has need of those environment variables. They can be accessed through the os.environ dict.

Upvotes: 1

Related Questions