Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 对于网络驱动器上的文件,os.path.isfile()返回false_Python_Python 2.7 - Fatal编程技术网

Python 对于网络驱动器上的文件,os.path.isfile()返回false

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

我试图使用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 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”)
?也会返回false
os.path.exists()返回什么?os.path.exists()返回falsetoo@TomCarroll好极了!很高兴我能帮你