类型错误:__init__() 得到了一个意外的关键字参数“严格" [英] TypeError: __init__() got an unexpected keyword argument 'strict'
问题描述
我在尝试运行我的脚本时遇到错误.我的脚本的目的是根据给它们的书签拆分 PDF 并将它们移动到特定文件夹中.
I am getting an error when trying to run my script. The purpose of my script is to split PDFs based on the bookmarks given to them and move them into specific folders.
但是,我在尝试阅读 PDF 时遇到此错误.
However I'm getting this error when trying to read the PDF.
Traceback (most recent call last):
File "I:\Harry\[Scripts]\013 - [Blackstone Changes]\3. Split Invoice & SuppDocs.py", line 280, in <module>
split(path, filename)
File "I:\Harry\[Scripts]\013 - [Blackstone Changes]\3. Split Invoice & SuppDocs.py", line 115, in split
pdf = pyPdf.PdfFileReader(open(os.path.join(path, filename), 'rb'), strict=False)
TypeError: __init__() got an unexpected keyword argument 'strict'
这是我的代码:
def split(path, filename):
idx = 1
name_fmt = 'CD_%s_%s.pdf'
with open('+Split.csv', 'ab') as fout:
writer = csv.writer(fout)
print os.path.join(path, filename)
pdf = pyPdf.PdfFileReader(open(os.path.join(path, filename), 'rb'), strict=False)
filename_no_ext, ext = os.path.splitext(filename)
invoice_folder = os.path.join('+Renamed', 'Invoice')
sdoc_folder = os.path.join('+Renamed', 'Supporting Docs')
try:
os.makedirs(invoice_folder)
except OSError:
pass
try:
os.makedirs(sdoc_folder)
except OSError:
pass
bookmark_list = list(bookmarks(pdf))
if not bookmark_list:
print '\t ->', os.path.join(invoice_folder, filename)
shutil.copy(
os.path.join(path, filename),
os.path.join(invoice_folder, filename)
)
return
errors = find_errors(bookmark_list)
if errors:
print >>sys.stderr, os.path.join(path, filename)
for error in errors:
print >>sys.stderr, error
print >>sys.stderr
return
有没有人对任何事情有任何想法可以帮助我?另外,我是 Python 的新手,所以试着为我把它变笨!谢谢!
Does anyone have any ideas on ANYTHING that might be able to help me? Also I'm new to Python so try and dumb it down for me! Thanks!
推荐答案
可能的原因是基于您陈述的错误
Likely cause is based on the error you stated
pdf = pyPdf.PdfFileReader(open(os.path.join(path, filename), 'rb'), strict=False)
这行不应该起作用不允许值strict所以它应该被删除或在其他地方使用.例如
this line shouldn't function doesn't allow the value strict so it should be removed or used elsewhere. For example
pdf = pyPdf.PdfFileReader(open(os.path.join(path, filename), 'rb'))
这篇关于类型错误:__init__() 得到了一个意外的关键字参数“严格"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!