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)

相关推荐
Taking_fish6 小时前
docker常见操作命令(基础服务搭建)
运维·docker·容器
m0_746752306 小时前
c++怎么利用std--variant处理多种二进制子协议包的自动分支解析【进阶】
jvm·数据库·python
m0_7349497913 小时前
MySQL如何配置定时清理过期备份文件_find命令与保留周期策略
jvm·数据库·python
简单点了14 小时前
全栈编程基础知识7
运维·服务器·网络
眷蓝天14 小时前
Docker 镜像瘦身:从 GB 到 MB 的优化实践
运维·docker·容器
实心儿儿14 小时前
Linux —— 进程控制 - mini shell
linux·运维·服务器
m0_5145205714 小时前
MySQL索引优化后性能没提升_通过EXPLAIN查看索引命中率
jvm·数据库·python
H Journey14 小时前
Python 国内pip install 安装缓慢
python·pip·install 加速
程序员黄老师14 小时前
Windows文件移动到Linux上的坑
linux·运维·服务器
shizhan_cloud14 小时前
自动化部署Kubernetes集群
运维·kubernetes