除了IOError为e:使用python 3但显示无效语法

时间:2017-08-15 15:11:44

标签: python-3.x

我编辑代码,似乎不是mising'try'的错误:

def load_letter(folder, min_num_images):
image_files = os.listdir(folder)
dataset = np.ndarray(shape=(len(image_files), image_size, image_size),
                     dtype=np.float32)
print(folder)
num_images = 0
for image in image_files:
    image_file = os.path.join(folder, image)
    try:
        image_data = (ndimage.imread(image_file).astype(float) - 
                pixel_depth / 2) / pixel_depth

        if image_data.shape != (image_size, image_size):
            raise Exception('Unexpected image shape: %s' % str(image_data.shape))
        dataset[num_images, :, :] = image_data
        num_images = num_images + 1

    except IOError as e:
        print('Could not read:', image_file, ':', e, '- it\'s ok, skipping.')
dataset = dataset[0:num_images, :, :]

我正在使用python 3而不是python 2,但它显示了这个错误:

except Exception as e:
     ^

SyntaxError:语法无效

我不明白为什么因为我正在使用py3

0 个答案:

没有答案