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)

相关推荐
小雨中_2 分钟前
3.1 RLHF:基于人类反馈的强化学习
人工智能·python·深度学习·算法·动态规划
The森8 分钟前
Linux IO模型纵深解析:文章索引
linux·运维·服务器
小李独爱秋24 分钟前
模拟面试:不能关机的情况下 , 如果挂载目录卸载不掉应该怎么办?
linux·运维·面试·职场和发展·操作系统·文件系统
锅包一切1 小时前
一、什么是Linux?
linux·运维·服务器·操作系统
Maggie_ssss_supp1 小时前
Linux-python
开发语言·python
ding_zhikai1 小时前
【个人日记】修复ubuntu屏幕显示不正常
linux·运维·ubuntu
学到头秃的suhian1 小时前
Docker基础扫盲
运维·docker·容器
Sunhen_Qiletian1 小时前
回归与分类的本质区别
人工智能·python
星星乘坐的船1 小时前
基于Kubernetes Python SDK实现Job创建
linux·python·kubernetes
yohalaser1 小时前
硬核智测赋能 武汉曜华激光加速钙钛矿产线产业化进程
大数据·运维·人工智能