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)

相关推荐
jufeng130710 分钟前
【系列:手搓自主 AI Agent:Hermes 架构原理剖析 · 第 7 篇】
python·ai agent·权限系统
梦想很大很大11 分钟前
如果有一个本地优先的 Workflow 工具,你们团队会愿意用吗?
python·agent·workflow
Elastic 中国社区官方博客18 分钟前
Elasticsearch:使用 AI Agent 来创建 workflow
大数据·运维·人工智能·elasticsearch·搜索引擎·自动化·全文检索
测试运维日常笔记27 分钟前
Linux系统安装配置TigerVNC服务器完整指南
linux·运维·服务器
用户83562907805139 分钟前
Python 自动化 Word 文本框处理:创建、定位、填充内容与管理
后端·python
喜欢的名字被抢了1 小时前
程序出问题怎么查,以及如何让它不掉线
java·运维·数据库
雾时之林1 小时前
Linux----cron定时服务
linux·运维·服务器
壹玖玖肆2 小时前
医院后勤智能运维系统实用性评测
运维
数据知道2 小时前
反序列化漏洞:Java、PHP、Python 三条线各讲透
java·网络·python·安全·网络安全·php
努力的小Qin3 小时前
梯度下降如何实现参数优化:从线性回归到 Sigmoid 分类
人工智能·python·神经网络