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)

相关推荐
lihui_cbdd13 小时前
HPC 集群上 OpenMM GPU 多版本安装实战指南
运维·服务器·人工智能·计算化学
隐于花海,等待花开13 小时前
16.Python 常用第三方库概览 深度解析
python
我材不敲代码13 小时前
Python 函数核心:位置参数与关键字参数详解
java·前端·python
风落无尘13 小时前
第十一章《对齐与安全》 完整学习资料
python·安全·机器学习
Kratzdisteln13 小时前
【无标题】
前端·python
hakesashou13 小时前
python文件操作需要导入模块吗
python
wuxinyan12313 小时前
工业级大模型学习之路029:解决双智能体调用数据库报错问题
数据库·人工智能·python·学习·智能体
志栋智能13 小时前
超越监控:超自动化巡检提供的主动价值
运维·网络·人工智能·自动化
SunnyDays101113 小时前
Python操作Excel批注:从基础添加到高级自定义的完整指南
开发语言·python·excel
独隅13 小时前
PyTorch自动微分模块:从原理到实战一
人工智能·pytorch·python