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)

相关推荐
Full Stack Developme6 小时前
JVM 与 Linux 交互的核心原理
linux·运维·jvm
Java识堂6 小时前
多级负载均衡架构
运维·架构·负载均衡
MXsoft6186 小时前
## 自动化巡检:从手工两小时到系统五分钟的落地实践
运维·自动化
ZLG_zhiyuan6 小时前
直击华南工博会|ZLG致远电子:EtherCAT与自动化总线应用方案动态实景呈现
运维·自动化
珺毅同学7 小时前
YOLO生成预测json标签迁移问题
python·yolo·json
HackTwoHub7 小时前
最新Nessus2026.6.8版本主机漏洞扫描/探测工具Windows/Linux
linux·运维·服务器·安全·web安全·网络安全·安全架构
骑士雄师7 小时前
18.4 长期记忆可修改版
python
~小先生~7 小时前
Python从入门到放弃(一)
开发语言·python
Nayxxu7 小时前
Gemini + RAG 企业知识库教程:从文档切片到答案生成
运维·人工智能
天佑木枫7 小时前
第2天:变量与数据类型 —— 让程序记住信息
python