Python的isfile()没有找到shell中存在的文件

时间:2016-03-23 20:37:04

标签: python python-imaging-library

我有一段代码试图打开一个图像文件,但是Image.open失败了 - 我添加了一个isfile()检查,并且在运行python脚本时仍然无法找到该文件。

但是,该文件确实与shell中的ls一起存在,或者直接从shell使用python解释器中脚本中的相同路径/文件。

from PIL import Image
import os

for x in range(0,10):

    file = work_dir + "/video" + str(x).zfill(4) + ".png"
    if os.path.isfile(file):
            print "file exists"
    else:
            print "file doesn't exit"

    print "opening file:" + file
    im = Image.open(file)
    im = im.resize((720,480))
    im = im.convert("RGBA")
    im.save(file)

让我们说work_dir =" / home / user"它报告/home/user/video0000.png但isfile()即使文件存在也找不到它!有什么我忽略的东西或调试方法吗?

0 个答案:

没有答案