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)

相关推荐
天天进步20152 分钟前
如何通过 Py_Initialize 实现 C++ 对 Python 的嵌入调用
python
Niuguangshuo5 分钟前
# PyTorch 中 `nn.ModuleList` 详解
人工智能·pytorch·python
BoBoZz1916 分钟前
ResetCameraOrientation 保存、修改和恢复摄像机的精确视角参数
python·vtk·图形渲染·图形处理
天竺鼠不该去劝架23 分钟前
金融智能体三大核心场景:银行运营、证券研究、保险理赔效率提升路径
人工智能·科技·自动化
aloha_78926 分钟前
python基础面经八股
开发语言·python
西西弗Sisyphus42 分钟前
极限的常数倍数性质证明和可视化代码
python·微积分·极限
心无旁骛~1 小时前
ModelEngine Nexent 智能体从创建到部署全流程深度体验:自动化利器让 AI 开发效率拉满!
运维·人工智能·自动化
G_H_S_3_1 小时前
【网络运维】OpenStack镜像管理:Glance篇
linux·运维·openstack
Muscleheng1 小时前
Linux安装LibreOffice
linux·运维·服务器