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)

相关推荐
Python私教5 分钟前
第一个Python金融爬虫
爬虫·python·金融
q***49457 分钟前
如何安装配置Goland并使用固定公网地址SSH远程连接本地服务器
运维·服务器·ssh
Stella252118 分钟前
【Jenkins/Termius/集群概念】
运维·servlet·jenkins
清清&25 分钟前
【Linux】冯诺依曼体系结构和操作系统的理解
linux·运维·服务器
Crazy________27 分钟前
37负载均衡介绍和nginx模块编译安装
运维·nginx·负载均衡
ZKNOW甄知科技1 小时前
重构企业运维智慧:低代码 ITSM 知识管理平台的创新与实践
大数据·运维·人工智能·程序人生·低代码·重构·it
nvd111 小时前
Python 迭代器 (Iterator) vs. 生成器 (Generator)
开发语言·python
HalvmånEver1 小时前
Linux:基础开发工具(三)
linux·运维·服务器·开发语言·学习·gcc/g++
老罗-Mason2 小时前
Apache Flink运行环境搭建
python·flink·apache
百***34132 小时前
Nginx实现接口复制
运维·nginx·junit