TypeError:__ init __()得到一个意外的关键字参数'strict'

时间:2018-04-20 10:14:19

标签: python python-2.7

我在尝试运行脚本时遇到错误。我的脚本的目的是根据给他们的书签拆分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的新手,所以试着为我愚蠢吧!谢谢!

1 个答案:

答案 0 :(得分:0)

可能的原因是基于您所说的错误

pdf = pyPdf.PdfFileReader(open(os.path.join(path, filename), 'rb'), strict=False)

此行不应该不允许值严格,因此应将其删除或在别处使用。例如

pdf = pyPdf.PdfFileReader(open(os.path.join(path, filename), 'rb'))