Can't get info on os.path attribute in python

752 views Asked by At

I'm trying to understand the expression structure of os.path.isdir

If type:

help(os)

I am provided with a list of 'things' python can use from os

I can't find an entry there called path rather pathconf(...)

However, when I type:

help(os.path)

The options I am provided include isdir(s)

Why am I not seeing information about path?

3

There are 3 answers

3
Mike Müller On

os.path is a module. Therefore it does not appear in the help for os. Rather it has its own help. os.path.__file__ will show you the actual path of this module. From the docs of os:

  • os.path is either posixpath or ntpath

Relevant part of the source of os:

if 'posix' in _names:
    # ...
    import posixpath as path
elif 'nt' in _names:
    # ...
    import ntpath as path
0
wim On

That's because the name path is not defined directly in the module os.py. Instead, it's imported from elsewhere and aliased. The implementation is platform-dependent.

On Windows systems you will have:

import ntpath as path

On Linux / macOS you will have:

import posixpath as path

Since os.path is just a reference to another module such as posixpath, or ntpath, you can always look at help(os.path).

0
mVChr On

os is /usr/lib/python2.7/os.py and os.path is /usr/lib/python2.7/posixpath.py (or ntpath.py on Windows). The help function simply reads the docstrings from those two files.