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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:28:08+00:00 2026-05-12T00:28:08+00:00

I was working with generator functions and private functions of a class. I am

  • 0

I was working with generator functions and private functions of a class. I am wondering

  1. Why when yielding (which in my one case was by accident) in __someFunc that this function just appears not to be called from within __someGenerator. Also what is the terminology I want to use when referring to these aspects of the language?
  2. Can the python interpreter warn of such instances?

Below is an example snippet of my scenario.

class someClass():
    def __init__(self):
        pass

    #Copy and paste mistake where yield ended up in a regular function
    def __someFunc(self):
        print "hello"
        #yield True #if yielding in this function it isn't called

    def __someGenerator (self):
        for i in range(0, 10):
            self.__someFunc()
            yield True
        yield False

    def someMethod(self):
        func = self.__someGenerator()
        while func.next():
            print "next"

sc = someClass()
sc.someMethod()

I got burned on this and spent some time trying to figure out why a function just wasn’t getting called. I finally discovered I was yielding in function I didn’t want to in.

  • 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-12T00:28:09+00:00Added an answer on May 12, 2026 at 12:28 am

    I’ll try to answer the first of your questions.

    A regular function, when called like this:

    val = func()
    

    executes its inside statements until it ends or a return statement is reached. Then the return value of the function is assigned to val.

    If a compiler recognizes the function to actually be a generator and not a regular function (it does that by looking for yield statements inside the function — if there’s at least one, it’s a generator), the scenario when calling it the same way as above has different consequences. Upon calling func(), no code inside the function is executed, and a special <generator> value is assigned to val. Then, the first time you call val.next(), the actual statements of func are being executed until a yield or return is encountered, upon which the execution of the function stops, value yielded is returned and generator waits for another call to val.next().

    That’s why, in your example, function __someFunc didn’t print “hello” — its statements were not executed, because you haven’t called self.__someFunc().next(), but only self.__someFunc().

    Unfortunately, I’m pretty sure there’s no built-in warning mechanism for programming errors like yours.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm asking this because I'm working with a recursive function that generates a large
This one is a long one, bellow is my primary class that holds the
Since the advent of AS3 I have been working like this: private var loggy:String;
I am working on an Android application, where some of the functions that users
I'm currently working on a Mips Code Generator for my Pascal Parser (Written in
I've been working on a very simple crud generator for pylons. I came up
I have been working on a LiftSuggest - an automatic Product Recommendations generator. Now,I
I'm working on a project(PHP Based) in which I need to compute SHA1, I'm
This is probably a noob question that I will get slated for but here
I'm working in Ruby, but I think this question is best asked agnostic of

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.