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)

相关推荐
No8g攻城狮11 分钟前
【Nginx】Nginx实现动态路由映射
运维·nginx
江畔何人初19 分钟前
LVM中物理卷、物理区块、卷组、逻辑卷的概念以及它们之间的关系
linux·运维·云原生·容器·kubernetes
小鸡吃米…19 分钟前
TensorFlow - TensorBoard 可视化
python·tensorflow·neo4j
凯子坚持 c25 分钟前
亮数据MCP结合Dify:构建自动化视频数据抓取与智能分析工作流的深度实践
运维·eureka·自动化
OPEN-Source40 分钟前
给 Agent 安装技能:工具抽象、自动选工具与安全边界
人工智能·python·agent·rag·deepseek
nxbsc_wanglc1 小时前
Linux安装redis
linux·运维·redis
ljxp12345681 小时前
高效删除链表重复节点
python
looking_for__1 小时前
【Linux】传输层协议UDP和TCP
linux·运维·tcp/ip·udp
52Hz1181 小时前
力扣207.课程表、208.实现Trie(前缀树)
python·leetcode
骇城迷影1 小时前
从零复现GPT-2 124M
人工智能·pytorch·python·gpt·深度学习