当前位置:网站首页>Error reporting solution - io UnsupportedOperation: can‘t do nonzero end-relative seeks
Error reporting solution - io UnsupportedOperation: can‘t do nonzero end-relative seeks
2022-07-06 11:07:00 【zkkkkkkkkkkkkk】
Catalog
Four 、seek Function introduction
One 、 Error code
with open(pdfpath,"r") as fp:
Two 、 Error message
PdfReadWarning: PdfFileReader stream/file object is not in binary mode. It may not be read correctly. [pdf.py:1143]
Traceback (most recent call last):
File "D:/Gitlab/my_world/recognize_img/pdf_to_img.py", line 36, in <module>
jiemi('D:\\Gitlab\\my_world\\recognize_img\\demo_img\\ The frameless table cannot be edited .pdf')
File "D:/Gitlab/my_world/recognize_img/pdf_to_img.py", line 9, in jiemi
pdfFile = PyPDF4.pdf.PdfFileReader(fp)
File "C:\Users\dell\Anaconda3\lib\site-packages\PyPDF4\pdf.py", line 1148, in __init__
self.read(stream)
File "C:\Users\dell\Anaconda3\lib\site-packages\PyPDF4\pdf.py", line 1754, in read
stream.seek(-1, 2)
io.UnsupportedOperation: can't do nonzero end-relative seeks
Process finished with exit code 1
Two 、 Solution
When reporting a mistake seek() An exception thrown by a function . resolvent : If you use open() Function to open a file ( For example, I use open() Function to open pdf), You have to use r+b How to read .
def read_pdf(file_path):
with open(pdfpath,"rb") as fp:
pdfFile = PyPDF4.pdf.PdfFileReader(fp)
print(pdf.pages)
fp.close()
if __name__ == '__main__':
file_path = 'D:\\Gitlab\\my_world\\recognize_img\\demo_img\\ The frameless table cannot be edited .pdf'
read_pdf(file_path)
Four 、seek Function introduction
This error is caused by seek() An exception thrown by a function .seek() Functions are common in reading files , It has the function of pointer . Usually in the process of reading documents , The pointer will then move to record the current read position .seek() Function can also move the pointer to the specified position .
seek Use of functions
fp.seek(0, 0) # first 0 Represents the offset , the second 0 Represents where to start the offset (0: From the beginning of the file ,1: From the current position ,2: From the end of the file .)
# Open file
with open("runoob.txt", "rw+") as fp:
line = fp.readline()
print(" Reading data :",line)
# Reset the file read pointer to the beginning
fp.seek(0, 0) # first 0 Represents the offset , the second 0 Represents where to start the offset (0: From the beginning of the file ,1: From the current position ,2: From the end of the file .)
line = fp.readline()
print(" Read data after reset :",line)
# Close file
fp.close()
边栏推荐
- Why can't I use the @test annotation after introducing JUnit
- Why is MySQL still slow to query when indexing is used?
- CSDN question and answer module Title Recommendation task (I) -- Construction of basic framework
- February 13, 2022-3-middle order traversal of binary tree
- Navicat 導出錶生成PDM文件
- Install mysql5.5 and mysql8.0 under windows at the same time
- 记某公司面试算法题:查找一个有序数组某个数字出现的次数
- MySQL21-用戶與權限管理
- @Controller, @service, @repository, @component differences
- 【博主推荐】asp.net WebService 后台数据API JSON(附源码)
猜你喜欢
QT creator specify editor settings
Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘
A brief introduction to the microservice technology stack, the introduction and use of Eureka and ribbon
Classes in C #
windows下同时安装mysql5.5和mysql8.0
CSDN问答标签技能树(一) —— 基本框架的构建
CSDN question and answer module Title Recommendation task (II) -- effect optimization
Windows cannot start the MySQL service (located on the local computer) error 1067 the process terminated unexpectedly
图片上色项目 —— Deoldify
Leetcode 461 Hamming distance
随机推荐
JDBC principle
Why is MySQL still slow to query when indexing is used?
Win10: how to modify the priority of dual network cards?
[untitled]
MySQL主从复制、读写分离
[number theory] divisor
Record a problem of raspberry pie DNS resolution failure
MySQL 20 MySQL data directory
自动机器学习框架介绍与使用(flaml、h2o)
CSDN问答标签技能树(二) —— 效果优化
CSDN question and answer module Title Recommendation task (II) -- effect optimization
【博主推荐】SSM框架的后台管理系统(附源码)
[BMZCTF-pwn] 11-pwn111111
记某公司面试算法题:查找一个有序数组某个数字出现的次数
February 13, 2022-2-climbing stairs
[Li Kou 387] the first unique character in the string
Ansible实战系列一 _ 入门
QT creator create button
La table d'exportation Navicat génère un fichier PDM
CSDN Q & a tag skill tree (V) -- cloud native skill tree