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)

相关推荐
qq_422828627 小时前
android图形学之SurfaceControl和Surface的关系 五
android·开发语言·python
南境十里·墨染春水7 小时前
linux学习进展 shell编程
linux·运维·学习
weixin_444012937 小时前
c++如何将std--vector直接DUMP到二进制文件_指针地址直写【附代码】
jvm·数据库·python
woxihuan1234568 小时前
Go语言中--=运算符详解:位右移赋值操作的原理与应用
jvm·数据库·python
goyeer8 小时前
【ITIL4】32服务实践 - 问题管理(Problem Management)
linux·运维·服务器·企业数字化·it管理·itil·it治理
石山代码8 小时前
Python 数据分析三大库:NumPy + Pandas + Matplotlib
python·数据分析·numpy
如竟没有火炬8 小时前
用队列实现栈
开发语言·数据结构·python·算法·leetcode·深度优先
元拓数智8 小时前
AI 自动化工作流,正在重塑企业数据工程的效率边界
大数据·人工智能·ai·自动化·工作流·数据工程
yivifu8 小时前
CustomTkinter的布局管理器介绍及应用
python·gui·customtkinter·pdf去水印
m0_690825828 小时前
如何备份被破坏的数据表_强制跳过错误的导出尝试
jvm·数据库·python