Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.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中的缩进错误导致语法错误_Python - Fatal编程技术网

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

Python中的缩进错误导致语法错误,python,Python,我在编译时遇到了这个错误。我知道为什么会发生这种情况,但由于我是新手,所以找不到解决方法。这个问题发生在生产线上 这是第二次编辑 文件“check.py”,第34行 缩进错误:应为缩进块 #!/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 #

我在编译时遇到了这个错误。我知道为什么会发生这种情况,但由于我是新手,所以找不到解决方法。这个问题发生在生产线上 这是第二次编辑

文件“check.py”,第34行

缩进错误:应为缩进块

#!/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()

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

这与缩进无关。您的代码中没有任何函数,那么您希望从中返回什么呢?您有一个
返回
,但是您确实为您展示的代码定义了一个函数吗?这实际上不是缩进问题。你认为
return
有什么作用?你想用
return
内部实现什么,除了
块之外?是的,我有,但我没有把它放在这里
#!/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()