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)

相关推荐
yz_aiks8 分钟前
chrome-use 使用教程:让 Claude Code 操控已登录的 Chrome(禅道、ONES 实测)
chrome·自动化·大模型·ai agent
一只爱撸猫的程序猿11 分钟前
全球出货第二,却不在 AI 的默认推荐里:一份悖论解剖报告
人工智能·python·产品
网络小江12 分钟前
组网第41课:ACL 门禁——标准/扩展、规则顺序、time-range、in/out 方向
运维·网络安全·acl·访问列表·in/out
piaoyiren15 分钟前
Python FTP 服务端项目详细功能文档
网络·数据库·python
miofly21 分钟前
GitHub 今日推荐|Edge0:让大号 MoE 模型在一台 Mac 上流式跑起来
python·开源·github
牛马工作号27 分钟前
Copyparty 轻量文件共享:Docker Compose 部署、权限与多协议使用全指南
运维·docker·容器
MyFreeIT32 分钟前
Python Windows Manual
开发语言·python
wusam39 分钟前
基于HCL的python脚本编程(2)
网络·python·智能路由器
神仙别闹1 小时前
基于Python+MySQL实现(Web)个人博客系统
python·mysql·php
二十七日秋1 小时前
算法刷题笔记「Day 1|四道 OJ 入门题里的深坑」
c语言·汇编·数据结构·c++·笔记·python·算法