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)

相关推荐
mortimer7 分钟前
破局视频翻译【最后一公里】––从语音克隆到口型对齐的完整工程思路
python·github·aigc
w***48822 小时前
Linux安装redis
linux·运维·redis
门框研究员2 小时前
解锁Python的强大能力:深入理解描述符
python
wanhengidc3 小时前
深度了解云手机是什么
运维·服务器·科技·智能手机·云计算
python百炼成钢3 小时前
28.嵌入式 Linux LED 驱动开发实验
linux·运维·驱动开发
子不语1803 小时前
Python——函数
开发语言·python
daidaidaiyu4 小时前
一文入门 LangChain 开发
python·ai
JJ1M85 小时前
用 Python 快速搭建一个支持 HTTPS、CORS 和断点续传的文件服务器
服务器·python·https
汤姆yu5 小时前
基于python大数据的小说数据可视化及预测系统
大数据·python·信息可视化
x***J3485 小时前
Python多线程爬虫
开发语言·爬虫·python