Python 对于网络驱动器上的文件,os.path.isfile()返回false
我试图使用os.path.isfile测试网络驱动器上是否存在文件,但即使文件存在,它也会返回false。你知道为什么会这样吗?或者我可以用其他方法来检查这个文件吗 我正在使用Python2.7和Windows10 这将返回true,因为它应该:Python 对于网络驱动器上的文件,os.path.isfile()返回false,python,python-2.7,Python,Python 2.7,我试图使用os.path.isfile测试网络驱动器上是否存在文件,但即使文件存在,它也会返回false。你知道为什么会这样吗?或者我可以用其他方法来检查这个文件吗 我正在使用Python2.7和Windows10 这将返回true,因为它应该: import os if os.path.isfile("C:\test.txt"): print "Is File" else: print "Is Not File" 即使文件存在,也返回false: import os if
import os
if os.path.isfile("C:\test.txt"):
print "Is File"
else:
print "Is Not File"
即使文件存在,也返回false:
import os
if os.path.isfile("Q:\test.txt"):
print "Is File"
else:
print "Is Not File"
来自python:
os.path模块始终是适合Python运行的操作系统的路径模块,因此可用于本地路径
尝试使用完整的UNC路径而不是映射的驱动器
import os
if os.path.isfile(r"\\full\uncpath\test.txt"):
print "Is File"
else:
print "Is Not File"
使用原始字符串:
os.path.isfile(r“Q:\test.txt”)
?也会返回falseos.path.exists()返回什么?os.path.exists()返回falsetoo@TomCarroll好极了!很高兴我能帮你