I see the code from nt import
in os.py
.
I want to see all those functions "with detailed code" in "nt".
For example mkdir()
is one of the functions in nt
.
How can I do this?
I see the code from nt import
in os.py
.
I want to see all those functions "with detailed code" in "nt".
For example mkdir()
is one of the functions in nt
.
How can I do this?
the nt
module seems to be a bit of a historical artifact, it's basically been merged into posixmodule.c
. it should instead be imported via the os
module for a very long time (i.e. before Python 2.0).
most of the functions there are native C code, so you'll need to to be relatively proficient in C to be able to understand what's going on. the Extending Python with C or C++ and maybe the Argument Clinic How-To sections in the docs have lots of relevant material
the actual C code behind those methods are in posixmodule.c
but its header file also does some parameter marshalling. native methods are defined by PyMethodDef
structures, but these can be somewhat obscured in older code bases like CPython
nt
is an OS-specific module, so you really shouldn't be using that. It may only be available on Windows.
Note that os
does actually import the right module into its own namespace (this is what from nt import *
does in its code when it runs on Windows, whereas it will do from posix import *
instead if it runs on Mac OS or Linux).
Therefore, you should actually just look at all the functions of os
.
Starting Python in interactive mode on the command line you can do this:
import os
help(os)
If you just want to see all names os
has to offer, you can do:
import os
print(dir(os))
If you specifically need help on mkdir
, you can also ask for help on this particular function:
import os
help(os.mkdir)
Most of the IDEs support this options.
Without the need to install anything - you can use ipython
for that.
Just start to write your requested module, .
and then press tab
, and the ipython
will display all the documented options.
You can find ipython.exe
at C:\[your-python]\scripts\ipython.exe
.
I'll advice to add this folder to your environment PATH
.