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)

相关推荐
维度攻城狮5 小时前
ros2参数通信案例
开发语言·windows·python·ros2·参数通信
深圳佛手5 小时前
不用智能体开发框架,如何调用工具?
前端·python
清水白石0085 小时前
Python 与尾递归:为何不优化?如何优雅绕过?
开发语言·python
zhengfei6115 小时前
AI渗透工具——AI驱动的自动化渗透测试框架 | 基于 Model Context Protocol (MCP) 架构
人工智能·架构·自动化
王大傻09285 小时前
使用python for循环与ord() + chr()实现字符串加密
开发语言·python
540_5405 小时前
ADVANCE Day35
人工智能·python·深度学习
郑泰科技6 小时前
python深度学习报错:Original error was: No module named ‘numpy.core._multiarray_umath‘
python·深度学习·numpy
chenyuhao20246 小时前
Linux网络编程:TCP协议
linux·运维·服务器·网络协议·tcp/ip·udp·tcp
不要em0啦6 小时前
从0开始学python:函数与数据容器
开发语言·python
csdnZCjava6 小时前
VMware 14无法连接 MKS: 套接字连接尝试次数太多;正在放弃
运维·服务器