python中的os.path.exists和os.path.isfile之间的区别 [英] Difference between os.path.exists and os.path.isfile in python

查看:505
本文介绍了python中的os.path.exists和os.path.isfile之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,当这两个函数返回不同的值。另外,如果你可以澄清一个不赞赏的路径/目录/文件之间的区别。

解决方案

正如你已经发现之间的差异存在 isfile 是事实,前者返回 True 如果给定的路径是一个目录一个文件,而后者只返回 True ,如果路径指向一个文件。



目录文件与技术观点非常相似。文件可以包含任何类型的数据。目录只是文件系统中的一个特殊条目(至少在Unix操作系统上它只是一个特殊文件),表示它可能包含文件和其他目录。这是建立数据结构的有用手段。使用目录,您可以按层次结构组织数据。



特别是在Windows环境中,目录通常称为文件夹。我确信你自己正在使用文件夹来组织你的文件。



路径是一个明确的指向文件中资源的指针系统。它可以指向一个文件或一个目录。


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.

解决方案

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.

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.

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.

这篇关于python中的os.path.exists和os.path.isfile之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆