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)

相关推荐
烟袅1 分钟前
为什么调用 OpenAI Tools 后,还要再请求一次大模型?——从代码看 LLM 工具调用的本质
后端·python·llm
GeekPMAlex2 分钟前
Python OOP 深度解析:从核心语法到高级模式
python
q***76665 分钟前
RustDesk搭建公网中继服务器远控内网机器(完整版)
运维·服务器
Sunhen_Qiletian19 分钟前
《Python开发之语言基础》第一集:python的语法元素
开发语言·python
速易达网络20 分钟前
tensorflow+yolo图片训练和图片识别系统
人工智能·python·tensorflow
WXDcsdn29 分钟前
联想台式机更换硬盘(Win10转Win7)后鼠标和键盘无法使用
运维·windows·it运维
讨厌下雨的天空36 分钟前
Linux信号
linux·运维·c++
守城小轩1 小时前
基于Chrome140的X账号自动化(关键词浏览)——运行脚本(三)
自动化·rpa·浏览器自动化·playwright·浏览器开发
weixin_446260851 小时前
n8n 工作流集合:解锁自动化新体验!
运维·自动化
淼_@淼1 小时前
pytest简介
运维·服务器·pytest