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)

相关推荐
2601_9679791225 分钟前
初学者必知的Python中优雅的用法
python·枚举·初学者·优雅用法·字典解析
AI创界者2 小时前
Python 进阶实战(五十八章):配置热更新、优雅停机排空与高并发压测方案
人工智能·python·aigc
AR-26710-3 小时前
docker Day3——镜像,容器,日志与元数据
运维·docker·容器
2601_967987376 小时前
python网络工程师自动化运维课程
python·正则表达式·网络工程师·模块·自动化运维
吴凡wudianmei6 小时前
给 LLM 套输出契约:校验失败怎么把错误回灌给模型
python·llm·agent
祺曦7 小时前
复现连续手语识别项目
python·手语识别·复现项目·corrnet
江润舟7 小时前
万物|炼器:从零手搓工业级旋转目标检测网络·卷7 —— OBB检测头与DFL解码(三)
人工智能·python·深度学习
AI创界者8 小时前
Python 进阶实战(五十六):KV Cache 驱逐闭环反馈与 Prefill / Decode 分离协同调度
人工智能·python·aigc
2601_967980118 小时前
Python - 变量作用域
python·闭包·变量作用域·nonlocal·嵌套函数
山楂树の9 小时前
Python 模块、包、面向对象编程
python