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)

相关推荐
江湖有缘10 小时前
Linux系统之htop命令基本使用
linux·运维·服务器
B***y88510 小时前
配置nginx访问本地静态资源、本地图片、视频。
运维·nginx
u***324313 小时前
使用python进行PostgreSQL 数据库连接
数据库·python·postgresql
ycydynq13 小时前
自动化验证码实现
爬虫·自动化
w***Q35013 小时前
Git工作流自动化
运维·git·自动化
吠品13 小时前
免费SSL证书自动化申请:DNS代理验证
网络协议·自动化·ssl
青瓷程序设计15 小时前
动物识别系统【最新版】Python+TensorFlow+Vue3+Django+人工智能+深度学习+卷积神经网络算法
人工智能·python·深度学习
tobebetter952715 小时前
How to manage python versions on windows
开发语言·windows·python
F_D_Z16 小时前
数据集相关类代码回顾理解 | sns.distplot\%matplotlib inline\sns.scatterplot
python·深度学习·matplotlib
xu_yule16 小时前
Linux_12(进程信号)内核态和用户态+处理信号+不可重入函数+volatile
linux·运维·服务器