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)

相关推荐
Decay__7 小时前
PostgreSQL 数据库全栈运维实战系列 — 合集索引(24 篇)
运维·数据库·sql·mysql·架构
戊本菌8 小时前
进程(三)runqueue 与 Linux 的 O(1) 调度
linux·运维·服务器
wuyk5558 小时前
Python办公自动化-第01讲-环境搭建与自动化认知
python·自动化·pyqt
高洁019 小时前
数字孪生与计算机视觉:让机器看懂现场
人工智能·python·机器学习·transformer·迁移学习
ComPDFKit9 小时前
RAG 回答只显示 PDF 文件名?用 Python 保留引用页码
开发语言·python·pdf·rag
yz_aiks11 小时前
Termux 使用教程:把安卓手机变成随身 Linux(装 Python、SSH 远程、跑自动化脚本)
android·linux·python·智能手机·ssh·termux
2601_9679801113 小时前
Flask Web 应用
python·flask·web开发·环境变量·虚拟环境
aifannihao13 小时前
ß 大写变 SS:用 Python 算清 Ruby2Shell 的缓冲区账本
python·安全·标准库·缓冲区溢出·字符串编码
csdn_aspnet13 小时前
在 Docker 容器中本地运行 SQL Server
运维·docker·容器·sqlserver
liwulin050613 小时前
【OLLAMA】调用SKILL的通用ReAct
python