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)

相关推荐
亮子AI12 小时前
【Python】比较两个cli库:Click vs Typer
开发语言·python
CappuccinoRose12 小时前
流计算概述
python·flink·流计算·数据流·pyflink
Dragon水魅12 小时前
Fandom Wiki 网站爬取文本信息踩坑实录
爬虫·python
Darkershadow12 小时前
蓝牙学习之unprovision beacon
python·学习·ble
小龙在山东12 小时前
基于 plumbum 跨平台执行Shell脚本
python
DeepFlow 零侵扰全栈可观测13 小时前
3分钟定位OA系统GC瓶颈:DeepFlow全栈可观测平台实战解析
大数据·运维·人工智能·云原生·性能优化
一点晖光13 小时前
jenkins 流水线脚本
运维·jenkins
济61713 小时前
linux(第九期)--交叉编译器-- Ubuntu20.04
linux·运维·服务器
zxdzxdzzxd13 小时前
Tailscale Linux 登录指南
linux·运维·服务器
CCPC不拿奖不改名13 小时前
python基础:python语言中的函数与模块+面试习题
开发语言·python·面试·职场和发展·蓝桥杯