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)

相关推荐
zhensherlock5 小时前
Protocol Launcher 系列:CodeHub 移动端 GitHub 协作利器
前端·javascript·typescript·node.js·自动化·github·js
鹤落晴春5 小时前
MySQL日志梳理
运维·数据库·mysql
承渊政道6 小时前
【Python编程快速上手—让繁琐工作自动化】(列表:把数据排成队,从下标取值到深拷贝)
开发语言·python·pycharm·自动化·列表
大胖爱学习_MJ6 小时前
Agent 如何安全地拿数据库密码?基于 HashiCorp Vault 的动态凭证下发
经验分享·python
zly35007 小时前
esxi安装 windows2000 鼠标不动
运维·服务器
tryCbest7 小时前
Python 爬虫从入门到实战(一):基础篇——从零写出第一个爬虫
开发语言·爬虫·python
无小道7 小时前
Python语句的特色
python·语句
2601_967980118 小时前
python pytest如何编写测试
python·测试用例·pytest·函数·assert
2601_967980119 小时前
Python中heapq模块的各种用法实例
数据结构·python·算法·应用实例·heapq模块
大胖爱学习_MJ9 小时前
超越向量检索:用 Spring Boot + Neo4j 手搓 GraphRAG 知识图谱记忆
java·后端·python