Python snippets (2)

1.
Generators

  1. def simpleGen():
  2.     yield 1
  3.     yield '2--->punch!'
  4.  
  5. myG = simpleGen()
  6. '''
  7. myG.next()
  8. myG.next()
  9. myG.next() #Exception
  10. '''
  11.  
  12. for eachItem in simpleGen():
  13.     print eachItem,
  14.  
  15. print '-----------------------------------------'
  16. from random import randrange
  17. def randGen(aList):
  18.     while len(aList) > 0:
  19.         yield aList.pop(randrange(len(aList)))# Just like list.pop() and random.choice()
  20.  
  21. for item in randGen(['rock', 'paper', 'scissors']):
  22.     print item

2.

  1. import longmodulename
  2. short = longmodulename
  3. del longmodulename
  4.  
  5. from cgi import FieldStorage as form

3.

1617042123[……]

Read more

宋之韵

《宋之韵》文字解说词

第一集 宋词概览
  一说宋词,我们立刻就会想到晏殊的,无可奈何花落去,似曾相识燕归来。想到欧阳修的,人生自是有情痴,此事不关风与月。想到晏几道的,今宵剩把银釭照,犹[……]

Read more