os是python的自带模块,可以在Lib目录下找到,那os.path算什么呢,为什么可以直接用import
os.path进行导入
阅读 lib 目录下的 posixpath.py 文件,有这么一段
"""Common operations on Posix pathnames.
Instead of importing this module directly, import os and refer to
this module as os.path. The "os.path" name is an alias for this
module on Posix systems; on other systems (e.g. Mac, Windows),
os.path provides the same operations in a manner specific to that
platform, and is an alias to another module (e.g. macpath, ntpath).
Some of this can actually be useful on non-Posix systems too, e.g.
for manipulation of the pathname component of URLs.
"""
因此 os.path 也是 Python 自带模块,是 posixpath 的别名,当然是在 Posix 系统下,如果在 Windows 系统下,则对应的是 ntpath