Skip to content

Instantly share code, notes, and snippets.

@davidbj
Created September 4, 2014 10:32
Show Gist options
  • Select an option

  • Save davidbj/784d5fb8a6baac0a9bfc to your computer and use it in GitHub Desktop.

Select an option

Save davidbj/784d5fb8a6baac0a9bfc to your computer and use it in GitHub Desktop.
python yield demo
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#Function: python yield demo
Queue=[1, 2, 3, 4, 5, 6]
def foo(regex):
print "start..."
while True:
var=(yield)
if var == regex:
print var
if __name__ == "__main__":
command = foo(4)
command.next() //echo "start..."
for i in Queue:
command.send(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment