2017-03-19 10 views
-2

コンパイル中にこのエラーが発生します。なぜそれが起こっているのかわかっていますが、私は初心者であるため解決策を見つけることができませんでした。この問題は、ライン 34で発生し、他の後.ThisはPythonのインデントが間違っているために構文エラーが発生しました

ファイル "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() 
+2

インデントとは関係ありません。あなたのコードには何も関数がありませんので、正確に何を返すと思いますか? – jonrsharpe

+2

あなたは 'return'を持っていますが、実際にあなたが示したこのコードのために定義された関数を持っていますか? – idjaw

+1

これは、実際にインデントの問題ではありません。 'return'はどうしたと思いますか? – user2357112

答えて

0

を期待しましたtryブロックからFalseを返す場合は、tryブロックを関数の中に入れる必要があります。 TestFunctionは、画像が良好かどうかをテストし、TrueまたはFalseを返します。 TestFunctionがTrueを返した場合は、次のステップに進みます。そうでない場合は、エラーメッセージを出力し、中断または終了します。

関連する問題