0
我認爲自己是python的初學者。我目前正在編寫代碼,它工作的很好。 問題是,爲了嵌入linux bash命令,需要使用大量的子進程庫調用。 這樣我就可以將1000行代碼重寫爲80行。 下面是我的一些代碼:是否適合編寫帶有大量調用python的子進程庫的代碼
if not OCRized(a):
p0=subprocess.check_call(["pdftk",a,"burst"])
print "splitting Pdf was successful........."
for i in range(len(pdf.pages)):
if (i>8):
nameBurst="pg_00"+str(i+1)+".pdf"
else:
nameBurst="pg_000"+str(i+1)+".pdf"
nameJPG="converted-"+str(i)+".jpg"
p1=subprocess.check_call(["convert","-density","300",nameBurst,"-depth","8",nameJPG])
print "Conversion to jpg was successful....."
nameHocr="converted-"+str(i)
p=subprocess.check_call(["tesseract",nameJPG,nameHocr,"-l","eng","hocr"])
print "tesseract did the job for the ",str(i+1),"page"
name2="page"+str(i)+".pdf"
p2=subprocess.check_call(["bash","-c","hocr-pdf .> reconstructed.pdf "])
print " Reconstruction is complete"
else:
p=subprocess.check_call(["tesseract",'1.png','f1',"-l","eng"])
所以可能這種方法可能會產生什麼問題? (代碼工作,但我仍然不相信)
當大多數腳本調用bash時,可能是時候考慮用bash編寫整個東西了。 – zondo
我想過,但我需要很多python funcionalities especillay調用某些API –