Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9273717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:10:47+00:00 2026-06-18T16:10:47+00:00

I have looked over quite a few posts on this here as well as

  • 0

I have looked over quite a few posts on this here as well as googling for it. I have used other languages but still learning Python and I’m also not as familiar with classes so I think I’m down to something I just don’t understand about the way classes act.

I wanted to work on an epub reading app and found roberto alasina’s project called integrate and it was a good starting point but it didn’t collect metadata and also the epub handling libs are not extracted enough for some of the other things I want to do. So I found dustjacket which is an epub reading class.

The reason I need to extract this further is I need to handle reads of data from multiple parts of the app and not just the reader itself. I plan on adding whoosh to it to enable searching and for the indexing I will need to read the chapters and then index the files. I can do this during the import of the book and don’t really need a gui for the actual indexing part.

Anyway in dist jacket I have added logging and I can see that my method is correctly grabbing the table of contents from the epub:

    def __parse_oebps(self, epub):
    '''Construct the chapter list assuming that the ePub has files in OEBPS/.'''

    # Parse the chapters
    npoints = self.__toc.findall("//{%(tocns)s}navPoint" % {'tocns': self.__namespaces['ncx']})
    for p in npoints:                   
        #rt = p.getroottree()
        #title = p.findtext("{%(tocns)s}text" % {'tocns': self.__namespaces['ncx']}) # Label text           
        title = p.find(
            '{http://www.daisy.org/z3986/2005/ncx/}navLabel').find(
                '{http://www.daisy.org/z3986/2005/ncx/}text').text
        contentfile = p.find("{%(tocns)s}content[@src]" % {'tocns':self.__namespaces['ncx']}).attrib['src'] # Contentfile name
        #if self.__has_oebps:
        #   #contentfile = "OEBPS/" + contentfile
        #   contentfile = "OEBPS/" + contentfile
        #   log.info("content file: %s", contentfile)

        #return contentfile 
        #self.chapters.append(EpubChapter(epub, p.attrib['id'], p.attrib['playOrder'], contentfile, title))
        if title and contentfile:
            log.debug("Title:        %s", title)
            log.debug("content file: %s", contentfile)
            self.chapters.append([title, contentfile])

    return self.chapters

I put in the debug logging and can easily see that the instance is properly called from the class and that the title and contentfile is there. this is from the ebubtoc class and is called from this method in the epub class:

    def __read_toc(self):
    '''Construct the table of contents for this epub'''
    self.__toc = EpubToc(self)
    for l, c in self.__toc:
        log.debug("Title:        %s", l)
        log.debug("content file: %s", c)

now when this method gets that data is when I get this error:

    for l, c in self.__toc:
TypeError: iteration over non-sequence

I have no idea at this point what I’m doing wrong and why this is not working. I can post the rest of the classes I’m using if this is not enough.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:10:48+00:00Added an answer on June 18, 2026 at 4:10 pm

    Your issue, as you show, is this line:

    for l, c in self.__toc:
    

    But self.__toc was declared to be:

    self.__toc = EpubToc(self)
    

    Bottom line is, you need to iterate over a list, not an object. Something like this should work, you might need a bit of tweaking to get it to work for your specific needs (possible the zip function, for instance)

    for c in self.__toc.get_chapter_titles():
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked all over but can't find an answer to this... Quite simply
Have looked quite hard for this answer but having no luck. I have 3
Ok, I have looked over and over this code but I can't seem to
I have looked all over and cannot figure out why this code isn't working.
I am re-hashing this question because I have looked at over 50 threads in
This may sound like a trivial question, however I have looked over the web
So I have looked over a bunch of other questions that could possible be
I don't really know why I have this issue, I have looked over my
I keep getting the same error: Missing Operator. I have looked over this code
I looked over Python Docs (I may have misunderstood), but I didn't see that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.