The listdir method is actually implemented in a C module, and is imported dynamically depending on the operating system environment. You can see the imports near the top of os.py, in blocks like this :
if 'posix' in _names:
name = 'posix'
linesep = '\n'
from posix import *
The
listdir
method is actually implemented in a C module, and is imported dynamically depending on the operating system environment. You can see the imports near the top ofos.py
, in blocks like this :Then the file
posixmodule.c
in the Python source has the POSIX implementation oflistdir
: https://github.com/python-git/python/blob/master/Modules/posixmodule.c#L2068 (and likewise for other OSes).