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)

相关推荐
岁月宁静1 小时前
一个 AI 项目从本地到上线,要经过哪些步骤?全流程讲清楚
python·docker·agent
奇树谦2 小时前
Windows CMD 下 mc 运维指南:SeaweedFS 安装验收与 MinIO 数据迁移
运维·windows
刚入门的大一新生2 小时前
Linux-信号
linux·运维·服务器
车软学堂2 小时前
CANoe自动化:跑起第一个测试用例
运维·车载系统·自动化·汽车·测试用例
codists2 小时前
《crafting interpreters》阅读笔记:p45-p45
python
曲径海盗3 小时前
【Python 学习第 41 天】for 循环
python·学习笔记·编程入门
摇滚侠3 小时前
《On Java 中文版 基础卷》阅读笔记 实现隐藏 11
java·笔记·python
沧海一笑-dj4 小时前
【Python】Python学习笔记-模块与包
python·pip·模块·包·python包·python模块·包与模块
L0208244 小时前
Kubernetes Ingress|CNI 网络模型|Calico 网络策略|Pod 调度器完整实战教程
运维·网络·云原生·容器·kubernetes