#!/usr/bin/python

#coding:utf-8

 

#print 'Hello world'

 

__metaclass__ = type

 

#class Fids:

#    def __init__(self):

#        self.a = 0

#        self.b = 1

#

#    def next(self):

#        self.a, self.b = self.b, self.a + self.b

#        return self.a

#

#    def __iter__(self):

#        return self

#

#fibs = Fids()

#for f in fibs:

#    print f

#    if f > 10:

#        break

#print fibs.next()

 

def flatten(nested):

    try:

        try: nested + ''

        except TypeError:

            print 'except '

            pass

        else:

            print 'else '

            raise TypeError

        for sublist in nested:

            for element in flatten(sublist):

                yield(element)

    except TypeError:

        yield nested

 

print list(flatten([[[1], 2], '376', 4, [5, [6, 7]], 8]))

 

def yield_test(n):

    for i in range(n):

        yield call(i)

        print 'i=', i

    print('do something.')

    print('end.')

 

def call(i):

    return i*2

 

for i in yield_test(5):

    print i, ','