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)

相关推荐
_Jimmy_3 小时前
Agent 溯源精度提升方案
人工智能·python·langchain
晚风吹长发4 小时前
Docker基础——Docker Network(网络详解)
linux·运维·网络·ubuntu·docker·容器
SamChan905 小时前
在Web应用中集成PDF多语言翻译功能:PDFTranslator API实战指南
前端·python·ai·pdf·yapi·机器翻译
天天进步20155 小时前
Python全栈项目--智能办公自动化系统
开发语言·python
阿三08125 小时前
跨境电商售后自动化分级标准:哪些能全自动、哪些半自动、哪些禁止自动化
大数据·人工智能·自动化
颜酱5 小时前
09 | 重构项目结构
人工智能·python·langchain
LedgerNinja6 小时前
WEEX API 自动化交易实践:下单、撤单、订单查询与状态闭环
运维·自动化
执笔画流年呀6 小时前
Linux搭建Java项目部署环境
java·linux·运维
kisloy6 小时前
【爬虫入门第8讲】Python爬虫反爬入门
开发语言·爬虫·python
Dory_Youth7 小时前
联想笔记本电脑失灵
运维·笔记·电脑