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)

相关推荐
花 满 楼几秒前
EB引脚配置自动化方案|告别手动繁琐配PIN,Excel+Python批量生成ARXML实现一键配置
python·excel·eb
江华森3 分钟前
jieba 分词 + 共现矩阵构建——《釜山行》人物关系提取(二)
python
techdashen5 分钟前
Uber 如何完成超大规模 JUnit 迁移:从 JUnit 4 到 JUnit 5 的自动化工程实践
junit·sqlserver·自动化
用户298698530149 分钟前
Python 实现 Excel 新旧格式互转:告别 Office 依赖的自动化方案
后端·python·excel
阿成学长_Cain18 分钟前
Linux grpck命令超全详解|校验组文件完整性、修复/etc/group错误实战
linux·运维·服务器·网络
进击切图仔19 分钟前
基于千问的白盒蒸馏 SOP
运维·服务器·人工智能·python·效率
2401_8685347820 分钟前
案例介绍-小型网络规划及搭
python·计算机网络
ONE_SIX_MIX29 分钟前
lightweight-charts-onesixth v2.8.1 → v3.1.1 更新总览
java·前端·python
YUS云生30 分钟前
Python学习笔记·第29天:Git进阶——分支操作与合并冲突
笔记·python·学习
杖雍皓32 分钟前
没有服务器如何构建现代 Web 应用:平台选型与组合策略
运维·服务器·前端·react.js·github·netlify·vercel