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)

相关推荐
安_7 小时前
如何构建和使用向量索引?HNSW 和 IVF 有什么区别?
python·ai
三言老师8 小时前
K8s集群运行时自动化运维全覆盖落地实操(下)
linux·运维·服务器·网络
counting money8 小时前
Java IO流详解:从InputStream到文件操作实战
java·开发语言·python
坚持学习前端日记9 小时前
Python SQLAlchemy ORM 从0到1精通实战手册(基础到复杂高阶)
数据库·python·oracle
北斗落凡尘9 小时前
LangGraph 入门实战(11)--输出模式
后端·python·langchain
雪碧聊技术10 小时前
安装Python(保姆级教程)
python·版本更新·python下载
躺不平的理查德10 小时前
嵌入式 Linux 系统移植与 SD 卡量产镜像制作
linux·运维·服务器
++==10 小时前
JSON和Python的 四种核心容器
python·json
一直走下去-明11 小时前
centos7无法安装tcpreplay
linux·运维
IT大白鼠11 小时前
n8n工作流自动化平台技术架构与应用价值评估
运维·架构·自动化·n8n