[英]Can't get info on os.path attribute in python
I'm trying to understand the expression structure of os.path.isdir
我试图了解
os.path.isdir
的表达结构
If type: 如果输入:
help(os)
I am provided with a list of 'things' python can use from os
我提供了python可以从
os
使用的``事物''列表
I can't find an entry there called path
rather pathconf(...)
我在那里找不到名为
path
的条目,而是pathconf(...)
However, when I type: 但是,当我键入:
help(os.path)
The options I am provided include isdir(s)
我提供的选项包括
isdir(s)
Why am I not seeing information about path
? 为什么我看不到有关
path
信息?
That's because the name path
is not defined directly in the module os.py
. 这是因为名称
path
未在os.py
模块中直接定义。 Instead, it's imported from elsewhere and aliased. 相反,它是从其他位置导入并使用别名的。 The implementation is platform-dependent.
该实现取决于平台。
On Windows systems you will have: 在Windows系统上,您将具有:
import ntpath as path
On Linux / macOS you will have: 在Linux / macOS上,您将具有:
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)
. 由于
os.path
只是对另一个模块(例如posixpath
或ntpath
,因此您始终可以查看help(os.path)
。
os.path
is a module. os.path
是一个模块。 Therefore it does not appear in the help for os
. 因此,它不会出现在
os
的帮助中。 Rather it has its own help. 相反,它有自己的帮助。
os.path.__file__
will show you the actual path of this module. os.path.__file__
将向您显示此模块的实际路径。 From the docs of os
: 从
os
的文档中:
- os.path is either posixpath or ntpath
os.path是posixpath或ntpath
Relevant part of the source of os
: os
来源的相关部分:
if 'posix' in _names:
# ...
import posixpath as path
elif 'nt' in _names:
# ...
import ntpath as path
os
is /usr/lib/python2.7/os.py
and os.path
is /usr/lib/python2.7/posixpath.py
(or ntpath.py
on Windows). os
是/usr/lib/python2.7/os.py
而os.path
是/usr/lib/python2.7/posixpath.py
(在Windows上是ntpath.py
)。 The help
function simply reads the docstrings from those two files. help
功能仅从这两个文件中读取文档字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.