iterating initalizations

r rt8396 at gmail.com
Tue Dec 23 04:38:29 CET 2008


>>> class test():
	def __init__(self, name):
		self.name = 'My name is %d' %name


>>> l = []
>>> for name in range(10):
	l.append(test(name))


>>> l
[<__main__.test instance at 0x02852E18>, <__main__.test instance at
0x02852C38>, <__main__.test instance at 0x028528A0>, <__main__.test
instance at 0x02852E90>, <__main__.test instance at 0x02852EE0>,
<__main__.test instance at 0x02852F30>, <__main__.test instance at
0x02852F80>, <__main__.test instance at 0x02852FD0>, <__main__.test
instance at 0x023AFC60>, <__main__.test instance at 0x02855030>]
>>> l[0].name
'My name is 0'
>>> l[1].name
'My name is 1'



More information about the Python-list mailing list