首页 新闻 搜索 专区 学院

一个简单的python包导入问题

0
悬赏园豆:5 [已解决问题] 解决于 2018-04-11 19:07

os是python的自带模块,可以在Lib目录下找到,那os.path算什么呢,为什么可以直接用import

os.path进行导入

xiaoblue的主页 xiaoblue | 初学一级 | 园豆:117
提问于:2018-04-10 20:49
< >
分享
最佳答案
0

阅读 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

收获园豆:5
_tison | 菜鸟二级 |园豆:207 | 2018-04-10 22:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册