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)

相关推荐
用户8356290780519 小时前
从手动编辑到代码生成:Python 助你高效创建 Word 文档
后端·python
c8i9 小时前
python中类的基本结构、特殊属性于MRO理解
python
東雪蓮☆10 小时前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs
qq_2642208910 小时前
LVS负载均衡群集和LVS+Keepalived群集
运维·负载均衡·lvs
liwulin050610 小时前
【ESP32-CAM】HELLO WORLD
python
乌萨奇也要立志学C++10 小时前
【Linux】进程概念(二):进程查看与 fork 初探
linux·运维·服务器
雨落Liy10 小时前
Nginx 从入门到进阶:反向代理、负载均衡与高性能实战指南
运维·nginx·负载均衡
Doris_202310 小时前
Python条件判断语句 if、elif 、else
前端·后端·python
Doris_202310 小时前
Python 模式匹配match case
前端·后端·python
Yyyy48211 小时前
Nginx负载均衡集群实验步骤
运维·nginx·负载均衡