I am new to python and I would like to know what this instruction is for:
ON_POSIX = 'posix' in sys.builtin_module_names
I know it might seem trivial to most of you but I could not find a clear explanation on the internet.
Thanks in advance for your help
From a high-level perspective you're checking if posix
module is built-in the Python Interpreter ( meaning compiled into the Python interpreter itself).
sys.builtin_module_names
returns a tuple of strings giving the names of all modules that are compiled into this Python interpreter.
If you take a look at the posix module :
import posix
help(posix)
You can see that this module is built-in :
Help on built-in module posix:
NAME
posix
FILE
(built-in)
MODULE DOCS
http://docs.python.org/library/posix
DESCRIPTION
This module provides access to operating system functionality that is
standardized by the C Standard and the POSIX standard (a thinly
disguised Unix interface). Refer to the library manual and
corresponding Unix manual entries for more information on calls.
By contrast you can do the same for os
module:
import os
help(os)
As you can see os in not compiled into the Python Interpreter FILE: /usr/lib64/python2.7/os.py
:
Help on module os:
NAME
os - OS routines for Mac, NT, or Posix depending on what system we're on.
FILE
/usr/lib64/python2.7/os.py