Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.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 在for循环后无法打印结果_Python_Python Imaging Library_Python 2.x_Pillow - Fatal编程技术网

Python 在for循环后无法打印结果

Python 在for循环后无法打印结果,python,python-imaging-library,python-2.x,pillow,Python,Python Imaging Library,Python 2.x,Pillow,我有以下Python代码: for root, dirs, files in os.walk(path): for file in files: image = Image.open(root + '/' + file).convert('L') label = label_img(file) X.append(image) y.append(label) files.append(file) print

我有以下Python代码:

for root, dirs, files in os.walk(path):
    for file in files:
        image = Image.open(root + '/' + file).convert('L')
        label = label_img(file)
        X.append(image)
        y.append(label)
        files.append(file)

print X
print y
print files
但是,我没有返回任何结果,运行程序的控制台冻结。知道我做错了什么吗?我在10个小图像上运行这个程序,所以输出应该相对较快。例如,如果我在循环中运行一些print语句,结果很快就会得到

for root, dirs, files in os.walk(path):  # files is a list
    for file in files:                   # file is out of files
        image = Image.open(root + '/' + file).convert('L')
        label = label_img(file)
        X.append(image)
        y.append(label)
        files.append(file)               # here you append file to files

您的文件列表越来越长-难怪它会冻结…

使用
os.path.join()
而不是字符串连接。进行一些调试如何<代码>打印文件?我在你的代码中既没有看到
X
也没有看到
Y
也没有
label\u img(…)
,但我认为它们可能很重要。。。。也许你应该把你的代码刷得整整齐齐。为什么要分解
文件
,然后对其进行迭代并将iter变量追加回文件?对于文件中的文件:。。。files.append(file)可能永远不会结束…不要使用相同的
文件
变量进行迭代和追加。