os.path.exists和os.path.isfile之间的区别? [英] Difference between os.path.exists and os.path.isfile?
问题描述
我很好奇这两个函数何时将返回不同的值。另外,如果您可以弄清路径/目录/文件之间的区别,将不胜感激。
I'm curious when these two functions will return different values. Also if you could clarify the difference between a path/directory/file that would be appreciated.
推荐答案
您已经发现,存在
和 isfile
之间的区别是前者返回 True
(如果给定路径是目录或文件),而如果路径指向文件,则后者仅返回 True
。
As you have already found out, the difference between exists
and isfile
is the fact that the former returns True
in case the given path is a directory or a file, while the latter only returns True
if the path points to a file.
目录和文件从技术角度来看非常相似。文件可以包含任何类型的数据。目录只是文件系统中的一个特殊条目(至少在Unix操作系统上,它只是一个特殊文件),它表示它可能包含文件和其他目录。这是建立数据结构的有用方法。使用目录,您可以按层次结构组织数据。
Directories and files are quite similar from the technical point of view. A file can contain any kind of data. A directory is just a special entry in the file system (at least on Unix operating systems it is just a special file) that represents the fact that it may contain files and other directories. It is a helpful means for building up a data structure. Using directories, you can organize your data in a hierarchical structure.
在Windows世界中,目录通常被称为文件夹。我确信您自己正在使用文件夹来组织文件。
Especially in the Windows world, directories are often called "folders". I am sure that you yourself are using "folders" for organizing your files.
路径是指向文件中资源的明确指针。系统。它可以指向文件或目录。
A path is an unambiguous pointer to a resource in the file system. It can either point to a file or to a directory.
这篇关于os.path.exists和os.path.isfile之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!