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
osmodule, so you won't find the definition inos.py. It's imported intoosfrom 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.systemcomes from thentmodule.You'll probably find that
os.system.__module__is either'nt'or'posix', representing either thentorposixmodule. The question then is, where are those modules defined? There's nont.pyorposix.py.It turns out these modules are implemented in C, in
Modules/posixmodule.c. Yes, thentmodule isposixmodule.c, and so is theposixmodule. It's weird.