【发布时间】:2019-07-17 21:55:21
【问题描述】:
尝试在 WinPython/Spyder 中使用 PyPDF2 时我无法解释错误消息
错误信息:
在[3]中:runfile('C:/Users/User/Downloads/WPy64-3720/pdf2text.py', wdir='C:/Users/User/Downloads/WPy64-3720')
代码:
import PyPDF2
path="C:\\Users\User\Downloads\WPy64-3720\soln.pdf"
text="C:\\Users\User\Downloads\WPy64-3720\Soln.text"
pdf_file = open(path, 'rb')
text =""
read_pdf = PyPDF2.PdfFileReader(pdf_file)
c = read_pdf.numPages
for i in range(c):
page = read_pdf.getPage(i)
text+=(page.extractText())
【问题讨论】:
-
这似乎不是一个完整的错误消息。你有剩下的部分吗?
-
这是 Spyder/WinPython 上的完整错误信息。
-
尝试将所有 \ 更改为
/。字符串中的 \ 是转义字符。 -
尝试了以下操作:
path=r"C:\Users\User\Downloads\WPy64-3720\soln.pdf" text=r"C:\Users\User\Downloads\WPy64-3720\soln.text"仍然收到以下错误消息,并且没有创建文本文件:In [16]: runfile('C:/Users/User/Downloads/WPy64 -3720/pdf2text.py', wdir='C:/Users/User/Downloads/WPy64-3720')