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)

相关推荐
idwangzhen9 分钟前
GEO优化系统哪家更专业
python·信息可视化
Fᴏʀ ʏ꯭ᴏ꯭ᴜ꯭.13 分钟前
Haproxy ACL实战:精准分流与访问控制
运维
RockHopper202521 分钟前
解读数字化生产运行系统的裁决机制
运维·系统架构·智能制造·isa-95·isa-88
diediedei26 分钟前
机器学习模型部署:将模型转化为Web API
jvm·数据库·python
m0_5613596728 分钟前
使用Python自动收发邮件
jvm·数据库·python
guizhoumen33 分钟前
2026年建站系统推荐及选项指南
大数据·运维·人工智能
naruto_lnq1 小时前
用Python批量处理Excel和CSV文件
jvm·数据库·python
yingdonglan1 小时前
鸿蒙跨端Flutter学习——GridView高级功能
linux·运维·windows
b2077211 小时前
Flutter for OpenHarmony 身体健康状况记录App实战 - 提醒设置实现
python·flutter·macos·cocoa·harmonyos
遇见火星1 小时前
在Linux中使用journalctl命令进行日志分析和管理详细教程
linux·运维·服务器·journalctl