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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:33:46+00:00 2026-05-13T07:33:46+00:00

i don’t know self._iterator = iter(self._container)in next code. in django.http : class HttpResponse(object): def

  • 0

i don’t know “self._iterator = iter(self._container)”in next code.

in django.http :

class HttpResponse(object):
    def __iter__(self):
        self._iterator = iter(self._container)
        return self

    def next(self):
        chunk = self._iterator.next()
        if isinstance(chunk, unicode):
            chunk = chunk.encode(self._charset)
        return str(chunk)

i read the api :

Return an iterator object. The first
argument is interpreted very
differently depending on the presence
of the second argument. Without a
second argument, o must be a
collection object which supports the
iteration protocol (the __iter__()
method), or it must support the
sequence protocol (the __getitem__()
method with integer arguments starting
at 0). If it does not support either
of those protocols, TypeError is
raised. If the second argument,
sentinel, is given, then o must be a
callable object. The iterator created
in this case will call o with no
arguments for each call to its next()
method; if the value returned is equal
to sentinel, StopIteration will be
raised, otherwise the value will be
returned. One useful application of
the second form of iter() is to read
lines of a file until a certain line
is reached. The following example
reads a file until “STOP” is reached:

but i also don’t know what the iter function made .

i know the __iter__:
class a(object):
    def __init__(self,x=10):
        self.x = x
    def __iter__(self):
        return self
    def next(self):
        if self.x > 0:
                self.x-=1
                return self.x
        else:
                raise StopIteration

Please try to use the code, rather than text, because my English is not very good, thank you

  • 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-05-13T07:33:47+00:00Added an answer on May 13, 2026 at 7:33 am

    An iterator can be iterated:

    for item in mylist:
        print item
    
    for key,item in enumerate(mylist):
        print key,":",item
    
    for i in range(0,50):
        print i
    

    To use for item in X, X must be iterable.

    You can make your class iterable by adding next(self) etc, as in your sample. So with

    class a(object):
        def __init__(self,x=10):
            self.x = x
        def __iter__(self):
            return self
        def next(self):
            if self.x > 0:
                self.x-=1
                return self.x
            else:
                raise StopIteration
    

    Then you can do

     ainst = a()
     for item in aisnt:
         print item
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 377k
  • Answers 377k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer He could simply grab the correct version of the java… May 14, 2026 at 9:00 pm
  • Editorial Team
    Editorial Team added an answer Well, so let me sum up: The eclipse wizard seems… May 14, 2026 at 9:00 pm
  • Editorial Team
    Editorial Team added an answer As matpol suggested, you can use css to do it,… May 14, 2026 at 9:00 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.