In my python standard library(Python 2.7
), I am looking for specific methods within the modules.
For e.g. if i open re.py
, i can see that there are specific methods like findall
,search
etc.
The same is evident when i do dir(re)
. I can clearly see the above methods.
Similarly,when i do dir(os)
, there exists a method called system
, which i usually call using os.system(cmd_name)
.
But when i look for this method under os.py
, it does not exist. Am i doing something wrong? Please guide
This function is not defined in the
os
module, so you won't find the definition inos.py
. It's imported intoos
from another module; which module that is will depend on your operating system. You can check:Here, you can see that since I'm on Windows,
os.system
comes from thent
module.You'll probably find that
os.system.__module__
is either'nt'
or'posix'
, representing either thent
orposix
module. The question then is, where are those modules defined? There's nont.py
orposix.py
.It turns out these modules are implemented in C, in
Modules/posixmodule.c
. Yes, thent
module isposixmodule.c
, and so is theposix
module. It's weird.