【发布时间】:2018-04-20 10:14:18
【问题描述】:
尝试运行我的脚本时出现错误。我的脚本的目的是根据给它们的书签拆分 PDF 并将它们移动到特定的文件夹中。
但是,我在尝试阅读 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
有人对ANYTHING有什么想法可以帮助我吗? 另外,我是 Python 新手,所以请尝试为我简化它!谢谢!
【问题讨论】:
-
什么是full错误回溯?
-
这是完整的回溯错误:回溯(最近一次通话最后一次):文件“I:\Harry[Scripts]\013 - [Blackstone Changes]\3. Split Invoice & SuppDocs.py”,行280,在
拆分(路径,文件名)文件“I:\Harry[Scripts]\013 - [Blackstone Changes]\3.Split Invoice & SuppDocs.py”,第 115 行,拆分 pdf = pyPdf.PdfFileReader( open(os.path.join(path, filename), 'rb'), strict=False) TypeError: __init__() got an unexpected keyword argument 'strict' -
编辑出现错误的问题。不要发布在 cmets 中
-
提供一些版本信息;
PdfFileReader被记录为具有严格的参数 pythonhosted.org/PyPDF2/PdfFileReader.html#PyPDF2.PdfFileReader -
我怀疑您使用的是 pyPDF1.3:pybrary.net/pyPdf,但正在阅读 pdPDF2 的文档:pythonhosted.org/PyPDF2/PdfFileReader.html
标签: python python-2.7