os.supports_bytes_environ

The os module has a Boolean flag that supports_bytes_environ. This flag is to indicate whether the environment variables of the operating system can be retrieved as bytes.

Os Updated 2 Apr 2021 1 min read

Overview

  • The os module provides the environment variables of the system as bytes(through os.environb) or as Unicode strings(through os.environ), except for the Windows operating system. In Windows, the collection of environment variables are dealt as Unicode strings(wchar_t of the windows operating system being the underlying). This behaviour is reflected through boolean flag supports_bytes_environ. The flag is set to False for Windows and assigned True otherwise. This is a low-level implementation detail which may change.

Example

python
# Example program that demonstrates the usage of the

            # os.supports_bytes_environ Boolean variable

            import os

print("Name of the os:%s"%os.name);

            print("Does the os support environment variables as bytes:%d"%os.supports_bytes_environ);

            print("Type of an item from the environment:");

            print(type(os.environb.__getitem__("PATH".encode())));

Output

Output
Name of the os:posix

Does the os support environment variables as bytes:1

Type of an item from the environment:

<class 'bytes'>