检查文件或路径 [Python]

Check if file or path [Python]

我正在尝试确定它是路径还是文件。

我用 python 的 os 库试过了。

path = '/home/User/Desktop/file.txt'
isFile = os.path.isfile(path)
print(isFile) -> False

为什么我得到的是假的而不是真的?

如果文件不存在,

os.path.isfile 将 return False。您可能还想查看 os.path.exists(path)