当前位置:网站首页>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()边栏推荐
- Mysql22 logical architecture
- Csdn-nlp: difficulty level classification of blog posts based on skill tree and weak supervised learning (I)
- [recommended by bloggers] asp Net WebService background data API JSON (with source code)
- QT creator specifies dependencies
- MySQL21-用戶與權限管理
- [recommended by bloggers] C MVC list realizes the function of adding, deleting, modifying, checking, importing and exporting curves (with source code)
- Copy constructor template and copy assignment operator template
- C language advanced pointer Full Version (array pointer, pointer array discrimination, function pointer)
- [Li Kou 387] the first unique character in the string
- JDBC原理
猜你喜欢
![[reading notes] rewards efficient and privacy preserving federated deep learning](/img/c3/5e88277b5024885d5ceeaa0de14b27.jpg)
[reading notes] rewards efficient and privacy preserving federated deep learning

A brief introduction to the microservice technology stack, the introduction and use of Eureka and ribbon
![[recommended by bloggers] C MVC list realizes the function of adding, deleting, modifying, checking, importing and exporting curves (with source code)](/img/b7/aae35f049ba659326536904ab089cb.png)
[recommended by bloggers] C MVC list realizes the function of adding, deleting, modifying, checking, importing and exporting curves (with source code)

打开浏览器的同时会在主页外同时打开芒果TV,抖音等网站
![[ahoi2009]chess Chinese chess - combination number optimization shape pressure DP](/img/7d/8cbbd2f328a10808319458a96fa5ec.jpg)
[ahoi2009]chess Chinese chess - combination number optimization shape pressure DP

Deoldify项目问题——OMP:Error#15:Initializing libiomp5md.dll,but found libiomp5md.dll already initialized.

自动机器学习框架介绍与使用(flaml、h2o)

CSDN question and answer module Title Recommendation task (I) -- Construction of basic framework

API learning of OpenGL (2002) smooth flat of glsl

图像识别问题 — pytesseract.TesseractNotFoundError: tesseract is not installed or it‘s not in your path
随机推荐
Postman environment variable settings
LeetCode #461 汉明距离
frp内网穿透那些事
Neo4j installation tutorial
CSDN markdown editor
CSDN question and answer tag skill tree (I) -- Construction of basic framework
neo4j安装教程
Timestamp with implicit default value is deprecated error in MySQL 5.6
Win10: how to modify the priority of dual network cards?
图像识别问题 — pytesseract.TesseractNotFoundError: tesseract is not installed or it‘s not in your path
csdn-Markdown编辑器
1. Mx6u learning notes (VII): bare metal development (4) -- master frequency and clock configuration
Detailed reading of stereo r-cnn paper -- Experiment: detailed explanation and result analysis
Development of C language standard
MySQL20-MySQL的数据目录
A brief introduction to the microservice technology stack, the introduction and use of Eureka and ribbon
Yum prompt another app is currently holding the yum lock; waiting for it to exit...
[Thesis Writing] how to write function description of jsp online examination system
CSDN博文摘要(一) —— 一个简单的初版实现
[recommended by bloggers] C MVC list realizes the function of adding, deleting, modifying, checking, importing and exporting curves (with source code)