Home > Back-end >  AttributeError: 'function' object as no attribute 'seek' with ebooklib package
AttributeError: 'function' object as no attribute 'seek' with ebooklib package

Time:10-03

This is my current code

import ebooklib
from ebooklib import epub

class EpubToTextClass:

    def __init__(self, dirToEpub=""):
        self.dirToEpub = dirToEpub

    def setDirToEpub(self, dirToEpub):
        self.dirToEpub = dirToEpub

    def convertEpubToText(self):
        book = epub.read_epub(self.convertEpubToText)
        items = list(book.get_items_of_type(ebooklib.ITEM_DOCUMENT))
        text = ""
        for i in items:
            text = text   i
        return text

ebpub = EpubToTextClass()
ebpub.setDirToEpub("-Some-EPUB.epub")
print(ebpub.convertEpubToText())

The goal of this part of the code is to convert a epub book to text, via the ebooklib but this error keeps popping up, and I am not completely sure what the error is about.

If you would like to see my whole error log, here it is:

Traceback (most recent call last):
  File "epubToText.py", line 22, in <module>
    print(ebpub.convertEpubToText())
  File "epubToText.py", line 13, in convertEpubToText
    book = epub.read_epub(self.convertEpubToText)
  File "/home/jeff/.local/lib/python3.8/site-packages/ebooklib/epub.py", line 1739, in read_epub
    book = reader.load()
  File "/home/jeff/.local/lib/python3.8/site-packages/ebooklib/epub.py", line 1397, in load
    self._load()
  File "/home/jeff/.local/lib/python3.8/site-packages/ebooklib/epub.py", line 1686, in _load
    self.zf = zipfile.ZipFile(self.file_name, 'r', compression=zipfile.ZIP_DEFLATED, allowZip64=True)
  File "/usr/lib/python3.8/zipfile.py", line 1269, in __init__
    self._RealGetContents()
  File "/usr/lib/python3.8/zipfile.py", line 1332, in _RealGetContents
    endrec = _EndRecData(fp)
  File "/usr/lib/python3.8/zipfile.py", line 264, in _EndRecData
    fpin.seek(0, 2)
AttributeError: 'function' object has no attribute 'seek'

CodePudding user response:

I figured it out later on.

Which was to change this:

book = epub.read_epub(self.convertEpubToText)

to

book = epub.read_epub(self.dirToEpub)
  • Related