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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:11:31+00:00 2026-06-13T22:11:31+00:00

I know Python has some lazy implementations, and as such, I was wondering if

  • 0

I know Python has some lazy implementations, and as such, I was wondering if it is possible to use circular programming in Python.

If it isn’t, why?

  • 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-13T22:11:32+00:00Added an answer on June 13, 2026 at 10:11 pm

    I think you mean co-routines, not co-recursion. Yes, it’s perfectly possible in Python, since PEP 342: Coroutines via Enhanced Generators has been implemented.

    The canonical example is the consumer decorator:

    def consumer(func):
        def wrapper(*args,**kw):
            gen = func(*args, **kw)
            next(gen)
            return gen
        wrapper.__name__ = func.__name__
        wrapper.__dict__ = func.__dict__
        wrapper.__doc__  = func.__doc__
        return wrapper
    

    Using such consumer then let’s you chain filters and push information through them, acting as a pipeline:

    from itertools import product
    
    @consumer
    def thumbnail_pager(pagesize, thumbsize, destination):
        while True:
            page = new_image(pagesize)
            rows, columns = pagesize / thumbsize
            pending = False
            try:
                for row, column in product(range(rows), range(columns)):
                    thumb = create_thumbnail((yield), thumbsize)
                    page.write(
                        thumb, col * thumbsize.x, row * thumbsize.y
                    )
                    pending = True
            except GeneratorExit:
                # close() was called, so flush any pending output
                if pending:
                    destination.send(page)
    
                # then close the downstream consumer, and exit
                destination.close()
                return
            else:
                # we finished a page full of thumbnails, so send it
                # downstream and keep on looping
                destination.send(page)
    
    @consumer
    def jpeg_writer(dirname):
        fileno = 1
        while True:
            filename = os.path.join(dirname,"page%04d.jpg" % fileno)
            write_jpeg((yield), filename)
            fileno += 1
    
    
    # Put them together to make a function that makes thumbnail
    # pages from a list of images and other parameters.      
    #
    def write_thumbnails(pagesize, thumbsize, images, output_dir):
        pipeline = thumbnail_pager(
            pagesize, thumbsize, jpeg_writer(output_dir)
        )
    
        for image in images:
            pipeline.send(image)
    
        pipeline.close()
    

    The central principles are python generators, and yield expressions; the latter lets a generator receive information from a caller.

    Edit: Ah, Co-recursion is indeed a different concept. Note that the Wikipedia article uses python for it’s examples, and moreover, uses python generators.

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

Sidebar

Related Questions

I know that Python’s Tk interface has some problems when using threads, and I’ve
I've already made a simple software with Python programming language. It has some libraries
As we know, Python has boolean values for objects: If a class has a
I have an open source project written in python , it has some Forms
I know that Python has built-in list functions but I'm curious as to how
I have some python module, which has a class ModuleClass and I can't modify
In this post , python has traceback library to get some detailed error information
I'm basically wondering if Python has any OOP shortcomings like PHP does. PHP has
As you know, python smtplib has a debug level.When I set it a true
I know python can be run on GAE what is different erlang and python

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.