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)

相关推荐
superrick5 分钟前
MCP 协议深度解析:AI Agent 的工具集成标准
python
淼澄研学30 分钟前
Python自动化办公实操:基于pandas与requests的5个提效场景解析
python·自动化·pandas
阳光九叶草LXGZXJ42 分钟前
达梦数据库-报错-11-cmd 13 validate error
linux·运维·数据库·sql·学习
~光~~1 小时前
【嵌入式linux学习_OV8858 bring up】L1_从Sensor到RK3588发生了什么
linux·运维·学习
运维大师1 小时前
【K8S 运维实战】32-GitOps实践ArgoCD
运维·kubernetes·argocd
薛少杰1 小时前
Python异步系统学习路线第59讲_核心原理与实战案例详解【技巧】
python·事件循环·异步编程·实战案例·协程调度
一次旅行1 小时前
fzf+ripgrep+fd终端三合一实战:一套检索工具链,大幅提升大型项目开发效率
人工智能·python·github
卷无止境1 小时前
当代码要上线前,谁在替你把关?——Python安全审查的方法论与实践
后端·python
Nuanyt1 小时前
Linux系统的 Shell 常见指令和常见知识点(以bash为主)
linux·运维·chrome·bash