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 8868481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:16:55+00:00 2026-06-14T17:16:55+00:00

So knowing what an iterator is, I’m assumign a string is an iterable object

  • 0

So knowing what an iterator is, I’m assumign a string is an iterable object because the following is possible:

for c in str:
  print c

I am subclassing str and overriding __hash__ and __eq__. In __hash__, I am trying to iterate over the string as follows:

for c in self.__str__:

The following error however returns: TypeError: 'method-wrapper' object is not iterable. This means that __str__ is not iterable. How do I get an iterable version of the string? I tried looking up some sort of str object API on Python but Python’s documentation only shows you how to use a string, and not what the internals are, and which object in str is iterable.

How can I iterate through my subclassed string, within my string object?

  • 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-14T17:16:57+00:00Added an answer on June 14, 2026 at 5:16 pm

    __str__ is another hook method, and not the value of the string.

    If this is a subclass of str, you can just iterate over self instead:

    for c in self:
    

    or you can make it more explicit:

    for c in iter(self):
    

    If this is not a subclass, perhaps you meant to call __str__():

    for c in self.__str__():
    

    or you can avoid calling the hook and use str():

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

Sidebar

Related Questions

Knowing about inaccuracies because of internal representation of floating point numbers (see Wikipedia ,
I am interested in knowing if the following scenario is a good use case
Knowing that I can't use HTMLAgilityPack, only straight .NET, say I have a string
Without knowing the keys of a JavaScript Object , how can I turn something
I am interested in knowing whether I can expect the observing object's method to
Knowing that anyone can see my AJAX URL string and or forms how can
I am interested in knowing if its even possible. One example is the variable
I have the following snippet of code. I'm basically trying to get the index/iterator
Is it possible (...knowing full well that this is crazy and seriously ill-advised...) to
Just wondering if knowing the original string length means that you can better unlash

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.