当前位置:网站首页>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()边栏推荐
- MySQL18-MySQL8其它新特性
- MySQL的一些随笔记录
- Classes in C #
- Postman environment variable settings
- Ansible实战系列三 _ task常用命令
- Ansible practical series I_ introduction
- Navicat 导出表生成PDM文件
- JDBC principle
- Are you monitored by the company for sending resumes and logging in to job search websites? Deeply convinced that the product of "behavior awareness system ba" has not been retrieved on the official w
- CSDN markdown editor
猜你喜欢

Win10: how to modify the priority of dual network cards?

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

CSDN Q & a tag skill tree (V) -- cloud native skill tree

QT creator specify editor settings

CSDN markdown editor

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

LeetCode #461 汉明距离

Redis的基础使用

打开浏览器的同时会在主页外同时打开芒果TV,抖音等网站

csdn-Markdown编辑器
随机推荐
Remember the interview algorithm of a company: find the number of times a number appears in an ordered array
IDEA 导入导出 settings 设置文件
Introduction to the easy copy module
Global and Chinese markets for aprotic solvents 2022-2028: Research Report on technology, participants, trends, market size and share
【博主推荐】C#MVC列表实现增删改查导入导出曲线功能(附源码)
MySQL主从复制、读写分离
Copy constructor template and copy assignment operator template
[C language foundation] 04 judgment and circulation
Postman uses scripts to modify the values of environment variables
Mysql21 user and permission management
机器学习--人口普查数据分析
Detailed reading of stereo r-cnn paper -- Experiment: detailed explanation and result analysis
windows无法启动MYSQL服务(位于本地计算机)错误1067进程意外终止
The virtual machine Ping is connected to the host, and the host Ping is not connected to the virtual machine
Install mysql5.5 and mysql8.0 under windows at the same time
Why can't I use the @test annotation after introducing JUnit
Some notes of MySQL
CSDN question and answer module Title Recommendation task (I) -- Construction of basic framework
Navicat 导出表生成PDM文件
@Controller, @service, @repository, @component differences