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)

相关推荐
无垠的广袤1 小时前
【工业树莓派 CM0 Dev Board】扩展板设计
linux·python·嵌入式硬件·pcb设计·模块化·传感器
Yolanda_20222 小时前
在vscode终端中可使用pip,但是cmd终端中找不到命令 pip问题的解决
vscode·python·conda·pip
2301_764441332 小时前
用动力学系统(微分方程)为 Kernberg 的客体关系单元提供数学化的操作定义,把“自体—客体“这对心理结构建模成一个二维耦合系统
数据结构·python·算法·数学建模
dogstarhuang3 小时前
用 Doubao-Seed-Evolving + Python 免费写一个网页正文提取工具(实战教程)
爬虫·python·ai编程
△曉風殘月〆3 小时前
如何在Linux中安装Qt开发环境
linux·运维·qt
猫头虎3 小时前
什么是ZCode for GLM-5.2?
开发语言·人工智能·python·科技·算法·ai编程·ai写作
心运软件3 小时前
Python实战:中国大学排行榜数据采集与可视化大屏
后端·python
长不胖的路人甲4 小时前
什么是赫夫曼树(哈夫曼树 / Huffman Tree)
python·算法·霍夫曼树
魔镜er4 小时前
03-张量
人工智能·pytorch·python
37.2℃9954 小时前
Claude Design哪个公司技术好
python·设计模式