对于os库,两者有什么区别?
os.listdir('.')vs os.listdir()
然而,它们似乎都会产生相同的结果( active directory中所有内容的列表):
https://www.tutorialspoint.com/python/os_listdir.htm
说os.listdir特别排除了‘’。和“..”即使它们存在于目录中。那是什么意思?
发布于 2017-11-06 03:14:17
发布于 2017-11-06 03:16:59
来自help os.listdir
listdir(path=None)
Return a list containing the names of the files in the directory.
path can be specified as either str or bytes. If path is bytes,
the filenames returned will also be bytes; in all other circumstances
the filenames returned will be str.
If path is None, uses the path='.'.也就是说,os.listdir()与os.listdir('.')相同。
...说
os.listdir特别排除了‘’。和“..”即使它们存在于目录中。那是什么意思?
这涉及到返回值。在UNIX文件系统中,每个目录都有.和..条目,其中.指的是当前目录,..指的是父目录。文档中说这些条目将不会包含在os.listdir返回的列表中。
发布于 2017-11-06 03:15:24
listdir()中的listdir.listdir点表示当前目录&当我们没有向()提供任何输入时,默认情况下,它会列出当前目录,这就是为什么它会显示相同的结果。在此处输入代码
https://stackoverflow.com/questions/47125522
复制相似问题