[英]What's the difference between: os.listdir('.') vs os.listdir()
For the os library what is the difference between 对于os库,有什么区别
os.listdir('.') vs os.listdir() os.listdir('。')与os.listdir()
They both seem to produce the same results (a list of everything in the active directory) however: 但是,它们似乎都产生相同的结果(活动目录中所有内容的列表):
https://www.tutorialspoint.com/python/os_listdir.htm https://www.tutorialspoint.com/python/os_listdir.htm
says that os.listdir specifically excludes '.' 说os.listdir特别排除'。' and '..' even if they are present in the directory.
和“ ..”,即使它们存在于目录中。 What does that mean?
这意味着什么?
From help 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='.'.
That is, os.listdir()
is the same as os.listdir('.')
. 也就是说,
os.listdir()
与os.listdir('.')
。
[...] says that
os.listdir
specifically excludes '.'[...]说
os.listdir
专门排除'。' and '..' even if they are present in the directory.和“ ..”,即使它们存在于目录中。 What does that mean?
这意味着什么?
That concerns the returned values. 那关系到返回的值。 In UNIX filesystems, every directory has
.
在UNIX文件系统中,每个目录都有一个
.
and ..
entries, where .
和
..
条目,其中.
refers to the current directory, and ..
to the parent directory. 指向当前目录,
..
指向父目录。 The documentation says that these entries will not be included in the list returned by os.listdir
. 文档说这些条目将不包含在
os.listdir
返回的列表中。
. 。 [dot] in listdir() refers to current directory & when we do not provide any input to listdir() then by default it lists current directory that's the reason it shows same result.
listdir()中的[dot]指向当前目录,并且当我们不向listdir()提供任何输入时,默认情况下它将列出当前目录,这就是它显示相同结果的原因。 enter code here
在这里输入代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.