1.RandSeq
#coding:utf-8 #!/usr/bin/env python 'randSeq.py -- 迭代' #从random模块里仅仅导入choice方法 from random import choice class RandSeq(object): def __init__(self,seq): self.data = seq; def __iter__(self): return self; def next(self): return choice(self.data) if __name__ == '__main__': for eachItem in RandSeq(('rock','paper','scisc')): print eachItem