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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:52:15+00:00 2026-06-08T07:52:15+00:00

I’m using the praw reddit library to pull data from reddit and I ran

  • 0

I’m using the praw reddit library to pull data from reddit and I ran into this bit of code that I don’t understand why it returns any data (inside the class BaseReddit (full source):

def get_content(self, page_url, limit=0, url_data=None, place_holder=None,
                root_field='data', thing_field='children',
                after_field='after'):
    """A generator method to return reddit content from a URL. Starts at
    the initial page_url, and fetches content using the `after` JSON data
    until `limit` entries have been fetched, or the `place_holder` has been
    reached.

    :param page_url: the url to start fetching content from
    :param limit: the maximum number of content entries to fetch. If
        limit <= 0, fetch the default_content_limit for the site. If None,
        then fetch unlimited entries--this would be used in conjunction
        with the place_holder param.
    :param url_data: dictionary containing extra GET data to put in the url
    :param place_holder: if not None, the method will fetch `limit`
        content, stopping if it finds content with `id` equal to
        `place_holder`.
    :param data_field: indicates the field in the json response that holds
        the data. Most objects use 'data', however some (flairlist) don't
        have the 'data' object. Use None for the root object.
    :param thing_field: indicates the field under the data_field which
        contains the list of things. Most objects use 'children'.
    :param after_field: indicates the field which holds the after item
        element
    :type place_holder: a string corresponding to a reddit content id, e.g.
        't3_asdfasdf'
    :returns: a list of reddit content, of type Subreddit, Comment,
        Submission or user flair.
    """
    content_found = 0

    if url_data is None:
        url_data = {}
    if limit is None:
        fetch_all = True
    elif limit <= 0:
        fetch_all = False
        limit = int(self.config.default_content_limit)
    else:
        fetch_all = False

    # While we still need to fetch more content to reach our limit, do so.
    while fetch_all or content_found < limit:
        page_data = self.request_json(page_url, url_data=url_data)
        if root_field:
            root = page_data[root_field]
        else:
            root = page_data
        for thing in root[thing_field]:
            yield thing
            content_found += 1
            # Terminate when we reached the limit, or place holder
            if (content_found == limit or
                place_holder and thing.id == place_holder):
                return
        # Set/update the 'after' parameter for the next iteration
        if after_field in root and root[after_field]:
            url_data['after'] = root[after_field]
        else:
            return

It looks to me like all the return statements have no arguments and therefore would default to returning None. Can someone explain this to me?

Note: Code is Python 2.x

  • 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-08T07:52:16+00:00Added an answer on June 8, 2026 at 7:52 am

    This is a generator function, which you can tell by the yield statement. The value is effectively ‘returned’ without actually returning from the function. When another value is requested from the function, the generator resumes from the point it yielded (as per the code below, continuing the for thing loop…).

    for thing in root[thing_field]:
        yield thing
    

    Simple example:

    def blah():
        for i in xrange(5):
            yield i + 3
    
    numbers = blah()
    print next(numbers)
    # lots of other code here...
    # now we need the next value
    print next(numbers)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.