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

  • Home
  • SEARCH
  • 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 7880229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:05:41+00:00 2026-06-03T04:05:41+00:00

This is a bit of an odd question; it came up in the context

  • 0

This is a bit of an odd question; it came up in the context of a tool that exposes a Python API, which we spend a lot of time querying interactively from the REPL. The particular idiom causing issues is something like this:

for var in slow_generator_of_giant_list():
    stats = update(stats, var)
print stats

To enter this at the REPL, I can type this:

>>> for var in slow_generator_of_giant_list():
...    stats = update(stats, var)
...

If I now attempt to type the print, I get a syntax error due to improper indentation. (Or else I put the print inside the loop and do it on every iteration.)

But if I hit enter to go to the next line, the loop runs immediately, and I have to wait for it to finish, or type the print command in the face of possible output coming at me, etc.

Obviously I can define a function containing the above, and it might be worth saving into a file anyway, but in the general case we’re constructing these on the fly, and it would be nice to have a way to “schedule” a command to run after the end of a loop from the REPL. In a language with block delimiters, I could of course put it after the ending delimiter (and any necessary statement separator). But my coworkers and I were stumped trying to do something similar here.

Is there perhaps an ugly abuse of Pythonic syntax that will do the trick that my coworkers and I couldn’t think of? Or a recommended way to avoid the problem while still making it easy to throw together ad hoc interactive queries?

Thanks for any pointers.

  • 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-03T04:05:42+00:00Added an answer on June 3, 2026 at 4:05 am

    Not beautiful, but this should work:

    >>> mygen = slow_generator_of_giant_list()
    >>> try:
    ...     while True: stats = update(stats, mygen.next())
    ... except StopIteration:
    ...     print stats
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a little bit odd question, but Im trying to figure out
This is a bit of an odd question and more of a though experiment
This might sound a bit of an odd question but I know what I
This may be a bit of an odd question, and what I have in
This is a bit of a an odd question but I'll make it out
This is a bit odd, but is it possible to use an NSCalendar (or
This is a bit of an odd situation. Here's what's happening. So, we have
This bit of code comes with new classes that are subclasses of UITableViewController... -
Bit of an odd question but I'm hoping someone can point me in the
This is a bit of an odd one. I'm trying to stub a method

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.