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)

相关推荐
AAD555888998 小时前
基于Faster RCNN的暴力行为检测模型优化与实现_1
python
难得的我们9 小时前
超越Python:下一步该学什么编程语言?
jvm·数据库·python
工程师老罗9 小时前
Turtle库的用法
python
诸神缄默不语9 小时前
当无法直接用apt instll时,Linux如何离线安装软件包(以make为例)
linux·运维·服务器
Sivan_Xin9 小时前
拒绝 If-Else 屎山:利用适配器模式(Adapter)构建第三方登录的“防腐层”实战
linux·python·适配器模式
learning-striving9 小时前
kali默认桌面Xfce切换为GNOME桌面
linux·运维·服务器·kali
黄昏晓x9 小时前
Linux----进程控制
android·linux·运维
郝亚军9 小时前
ubutnu 64位系统,需要安装的工具包
linux·运维·ubuntu
宇钶宇夕9 小时前
CoDeSys入门实战一起学习(二十八):(ST)三台电机顺起逆停程序详解
运维·学习·自动化·软件工程
AI Echoes9 小时前
LangChain Runnable组件重试与回退机制降低程序错误率
人工智能·python·langchain·prompt·agent