python自动化办公之PyPDF2.errors.DeprecationError

背景:pypdf2库在不断更新换代里面的类,逐渐淘汰一些旧的类

PyPDF2.errors.DeprecationError的意思是我们代码里用到的类计划被淘汰了,系统不推荐使用,解决办法:根据提示use xxx instead使用xxx 替换之前的类

例子1

PyPDF2.errors.DeprecationError: PdfFileReader is deprecated and was removed in PyPDF2 3.0.0. Use PdfReader instead.

原代码

python 复制代码
# 创建pdf文件阅读器对象
reader=PyPDF2.PdfFileWriter(file)

修改后

reader=PyPDF2.PdfReader(file)

例子2

PyPDF2.errors.DeprecationError: reader.numPages is deprecated and was removed in PyPDF2 3.0.0. Use len(reader.pages) instead.

原代码

python 复制代码
# 获取pdf文件的总页数
total_pages=reader.numPages

修改后

total_pages=len(reader.pages)

相关推荐
Cachel wood12 小时前
hands-on-modern-rl:动手学强化学习策略梯度reinforce
开发语言·python
蓝斯49712 小时前
一碰即传,重构跨设备文件分享体验
开发语言·python·重构
寒水馨12 小时前
macOS下载、安装uv-0.12.0(附安装包uv-aarch64-apple-darwin.tar.gz)
python·macos·rust·项目管理·包管理器·astral·pip替代
三言老师12 小时前
awk条件筛选日志内容实操
linux·运维·服务器·centos
^yi12 小时前
【Linux系统编程】库的制作与使用
linux·运维·服务器
WA内核拾荒者13 小时前
WhatsApp 对话内容的质量评估体系与自动化检测方案
大数据·人工智能·自动化
深耕时光,自成山海13 小时前
for,while等循环
运维
曦尧13 小时前
Zabbix:企业级开源分布式监控系统深度解析
ai·自动化
bksczm13 小时前
popen解析
linux·运维·服务器