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)

相关推荐
Patrick在香港几秒前
第 16,216 次连接之后,它不干了
python·网络编程·socket·tcp·连接池
我命由我123455 分钟前
Python 开发 - Python 虚拟环境
运维·开发语言·后端·python·http·https·java-ee
dlhto13 分钟前
Windows 使用 Rufus 制作 AlmaLinux 10.2 启动 U 盘:从 ISO 下载到服务器安装
运维·服务器·windows
软件派17 分钟前
Beam.Win 自动化办公与业务流程提效指南
运维·自动化
云和数据.ChenGuang19 分钟前
LLM大模型对接本地Ollama部署模型
开发语言·人工智能·python·langchain
星禾元亨20 分钟前
用结构化数据与干净实体信号,让技术内容被 AI 搜索引擎稳定引用
数据库·人工智能·自动化·创业创新
澜山奕秋1 小时前
Rhcsa 二
linux·运维·服务器
云和数据.ChenGuang1 小时前
光哥说Python 循环导入(Circular Import)深度解析:成因、排查与解决方案
开发语言·前端·人工智能·python·langchain
无足鸟ICT1 小时前
【RHCA+】yum源配置(软件仓库)
linux·运维
TomEval1 小时前
【测AI】第16篇:模型公平性与可解释性测试 — AI 的偏见与黑箱
人工智能·python·功能测试·ai·测试用例