[英]What's the difference between: os.listdir('.') vs os.listdir()
对于os库,有什么区别
os.listdir('。')与os.listdir()
但是,它们似乎都产生相同的结果(活动目录中所有内容的列表):
https://www.tutorialspoint.com/python/os_listdir.htm
说os.listdir特别排除'。' 和“ ..”,即使它们存在于目录中。 这意味着什么?
从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
返回的列表中。
。 listdir()中的[dot]指向当前目录,并且当我们不向listdir()提供任何输入时,默认情况下它将列出当前目录,这就是它显示相同结果的原因。 在这里输入代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.