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)

相关推荐
Chen放放3 小时前
【华三】VXLAN-三层集中式网关配置
运维·网络
碎梦归途3 小时前
思科网络设备配置命令大全,涵盖从交换机到路由器的核心配置命令
linux·运维·服务器·网络·网络协议·路由器·交换机
七维大脑虚拟机3 小时前
飞牛NAS公网IPv6+DDNS远程访问零延迟教程
运维·服务器·网络
rayufo3 小时前
【工具】列出指定文件夹下所有的目录和文件
开发语言·前端·python
缺点内向4 小时前
C#编程实战:如何为Word文档添加背景色或背景图片
开发语言·c#·自动化·word·.net
AZ996ZA4 小时前
自学linux第十八天:【Linux运维实战】系统性能优化与安全加固精要
linux·运维·安全·性能优化
Python 老手4 小时前
Python while 循环 极简核心讲解
java·python·算法
开源技术5 小时前
如何将本地LLM模型与Ollama和Python集成
开发语言·python
weixin_437044645 小时前
Netbox批量添加设备——堆叠设备
linux·网络·python
hhy_smile5 小时前
Ubuntu24.04 环境配置自动脚本
linux·ubuntu·自动化·bash