python os.path.isfile返回值为false

python os.path.isfile返回值为false,python,Python,我正在尝试从不同的目录中搜索文件。我看到该文件确实存在,但os.path.isfile仍然返回false 因为我的文件可以在多个目录中 import os me = "/user" my_home = "/home" my_direcotry = "/user/jsbt" my_file = "/myfile" my_path = me + my_home + my_directory + my_file print(my_path) if (os.path.isfile( my_pa

我正在尝试从不同的目录中搜索文件。我看到该文件确实存在,但os.path.isfile仍然返回false

因为我的文件可以在多个目录中

import os

me = "/user"
my_home = "/home"
my_direcotry = "/user/jsbt"
my_file =  "/myfile"

my_path = me + my_home + my_directory + my_file

print(my_path)

if (os.path.isfile( my_path )) is True:
print ("Path was found")
else:
print ("Path does not exist")
sys.exit(0)
上述操作总是导致false,并且无法找到该文件

但我确实找到了我的文件


有什么建议吗

将扩展名添加到my_文件并检查路径是否正确

还有,不要用是真的。改为:

if (os.path.isfile( my_path )): # OR == True
    print ("Path was found")
    else:
    print ("Path does not exist")
    sys.exit(0)

如果将isfile替换为exists,会发生什么情况?如果您执行
cat/user/home/user/jsbt/myfile
我也尝试过使用exists,但使用的是相同的东西,该怎么办。。它的结果是false。那么
cat/user/home/user/jsbt/myfile
呢?它真的找到文件了吗?上面显示的代码将导致多个错误,而不仅仅是缩进错误。向我们展示你实际使用的代码。对不起,各位输入错误。。我的错。。python新手,并且已经爱上了它。:)修好了。