由于Python中的错误缩进导致语法错误

时间:2017-03-19 23:45:39

标签: python

我在编译时遇到这个错误。我知道它为什么会发生但却无法找到解决方案,因为我是新手。这个问题发生在行 34以及其他。这是第二次编辑

文件" check.py",第34行

else:
   ^

IndentationError:预期缩进块

#!/usr/bin/python
# -*- coding: utf-8 -*-
from wand.image import Image
from PIL import Image as Img
import os
import sys
import numpy as np
import glob

 # put all resume in a directory (inp_dir)

inp_dir = '/home/sameer/Downloads/resumes/resume_v7/'

# expect all txt files in this dir (out_dir)

out_dir = './pdf_img3/'

# filenames in all_resumes folder

filename1 = [x for x in os.listdir(inp_dir)]
for f in filename1:
    try:
        with Image(filename=inp_dir + f, resolution=200) as img:

        # keep good quality

            img.compression_quality = 80
            f = f.split('.')[0]
            img.save(filename='%s%s.jpg' % (out_dir, f))


    except Exception as err:
        print err
    else:

        pathsave = []
        try:
            #print 'there must be 2 pages in the pdf'
            list_im = glob.glob('%s/%s*.jpg' % (out_dir, f))
            list_im.sort()  # sort the file before joining it
            imgs = [Img.open(i) for i in list_im]

            # now lets Combine several images vertically with Python

            min_shape = sorted([(np.sum(i.size), i.size) for i in
                           imgs])[0][1]
            imgs_comb = np.vstack(np.asarray(i.resize(min_shape))
                              for i in imgs)

             # for horizontally  change the vstack to hstack

            imgs_comb = Img.fromarray(imgs_comb)
            pathsave = '%s%s-f.jpg' % (out_dir, f)

            # now save the image

            imgs_comb.save(pathsave)

            # and then remove all temp image

            for i in list_im:
               os.remove(i)
        except Exception as err:
            exit()

1 个答案:

答案 0 :(得分:0)

如果要从try块返回False,则需要在函数内部使用try块。 TestFunction将测试图像是否良好并返回True或False。如果TestFunction返回True,则继续执行下一步,否则打印错误消息并中断或退出。