Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.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中传递给Exists函数的参数_Python_Python 2.7 - Fatal编程技术网

在python中传递给Exists函数的参数

在python中传递给Exists函数的参数,python,python-2.7,Python,Python 2.7,无法理解此错误 Traceback (most recent call last): File "ex4.py", line 6, in <module> print "does the file exsts %r" % exists(src_file) File "C:\Python27\lib\genericpath.py", line 26, in exists os.stat(path) TypeError: coercing to Unico

无法理解此错误

    Traceback (most recent call last):
  File "ex4.py", line 6, in <module>
    print "does the file exsts %r" % exists(src_file)
  File "C:\Python27\lib\genericpath.py", line 26, in exists
    os.stat(path)
TypeError: coercing to Unicode: need string or buffer, file found
os.path.exists()。您传入了一个open file对象(调用
open(source)
的结果)

您可以使用
source
,其中包含您的文件名:

print "does the file exists %r" % exists(source)
由于您已经成功地从文件名打开了该文件,因此测试该文件是否存在几乎没有意义

print "does the file exists %r" % exists(source)