Python equivalent of continuations with Ruby

What is the Python equivalent of the following code in Ruby?

def loop
  cont=nil
  for i in 1..4
    puts i
    callcc {|continuation| cont=continuation} if i==2
  end
  return cont
end

> c=loop
1
2
3
4
> c.call
3
4

Reference: Secrets of lightweight development success, Part 9: Continuations-based frameworks

Answers


The article you quoted contains a link to Continuations Made Simple And Illustrated in the Resources section, which talks about continuations in the Python language.


Need Your Help

Preg Match for strings inside square brackets and @strings

php regex preg-match

I would like to get strings inside [square] [brackets] and also those @like @this. The following works for the [tags] but not the @users.

Can't keep overlay out of sight once it has transitioned

css

I will eventually have a grid of embedded YouTube videos on a grid that are each initially covered by an overlay that will contain information about the relevant video. On hovering over the overlay...