gpt4 book ai didi

python - pyPdf 错误参数无效

转载 作者:太空狗 更新时间:2023-10-30 01:38:43 25 4
gpt4 key购买 nike

我实际上是在使用 pyPdf 打开、读取和写入 PDF 文件的内容。

为此,我使用了这些代码行:

from pyPdf import PdfFileWriter, PdfFileReader

pdf = PdfFileReader(file("/myPdfFile.pdf", "w+b"))
content = pdf.getPage(1).extractText()
print content

但是它返回了这个错误,我不明白为什么

File "/usr/local/lib/python2.6/dist-packages/pyPdf/pdf.py", line 374, in __init__
self.read(stream)
File "/usr/local/lib/python2.6/dist-packages/pyPdf/pdf.py", line 702, in read
stream.seek(-1, 2)
IOError: [Errno 22] Invalid argument

谁能帮帮我?

最佳答案

正如 Python 文档中所述,模式 'w+b' 打开文件并将其截断为 0 字节,而 'r+b' 打开文件没有截断。

关于python - pyPdf 错误参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10706778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com