This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 8th, 2012  |  syntax: Python  |  size: 0.28 KB  |  views: 71  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # in stackless python or pypy
  2. def repeat(item):
  3.     i = 0
  4.     while True:
  5.         yield i, item
  6.         i += 1
  7.  
  8. import pickle
  9. gen = repeat('foo')
  10. print gen.next() # (0, 'foo')
  11. dumped = pickle.dumps(gen)
  12. # and in another machine
  13. gen = pickle.loads(dumped)
  14. print gen.next() # (1, 'foo')
clone this paste RAW Paste Data