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)

相关推荐
心静财富之门12 小时前
Python 数据共享四种方案完整实例(同进程 / JSON / Redis / HTTP)
数据库·python·oracle
讯捷蓝达12 小时前
IBM V3500存储 双控故障、数据怎么恢复?
运维
王仔小奶12 小时前
慢SQL治理与性能调优:DBA如何用Shell/Python提升运维效率?
python·sql·dba
用户03321266636712 小时前
使用 Python 快速在 PowerPoint 中生成表格【教程】
python
夜晚回家13 小时前
Python 身份运算符详解 | is 与 == 到底差在哪
python
fengye20716113 小时前
cpython框架结构
python
qq_谁赞成_谁反对13 小时前
甲方IT的成长之路--SG TCP网络优化工具--20261026
运维·服务器·udp·tcp
用户912940468484213 小时前
大模型返回 JSON 后,先过这道 Python 校验
python
Dmz丶13 小时前
前端转 AI 100 天 Day 32:LLM 客户端工程化——重试、超时、降级、限流
python
曲径海盗13 小时前
【Python 学习第 39 天】for 循环
python·学习笔记·编程入门