2010年9月25日土曜日

インスタンスをリストに持たせる。

複数のインスタンスを作った場合に、管理するのに便利そう。

http://blogs.yahoo.co.jp/nanashi_hippie/47503485.html



class hello:
def __init__(self, num):
self.num = num
print 'hello init'

def output(self):
print 'hello output', self.num


def main():
pack = []

test1 = hello(5)
test2 = hello(10)

pack.append(test1)
pack.append(test2)

print pack
for x in [0,1]:
pack[x].output()

pack.pop(0)
pack[0].output()

return

if __name__ == '__main__': main()