[Tutor] Creating multiple instance names

Lugo Teehalt lugoteehalt@yahoo.co.uk
Fri Mar 14 11:15:04 2003


--0-2096850781-1047658352=:88177
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit


 

Is it possible to use 'for' or 'while' or the like to create

arbitrarilly many named class instances? Tried to do something

like:

for i in ['a', 'b', 'c', 'd']:

i = Counter()                #Counter being a class

print a.y, b.y, c.y, d.y   # y is a thing from the class e.g. self.y = 0.

(i.e. I'm trying to create four instances named a, b, c and d.)



This sort of thing does't work. Assume it just shoves a new 'value'

into the single 'pidgeon hole' named i every time.

Is this just a special case of the general problem of how to name

a sequence of 'cubby-holes', and put a specific

value into each one, instead of naming one cubby-hole and putting a

sequence of new values into it? I know how to create a sequence of pidgeon

hole contents but not how to create a sequence of named pidgeon holes.

Don't think this is bollocks; hope not.




---------------------------------
With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits your needs

--0-2096850781-1047658352=:88177
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

<P>&nbsp;</P>
<P>Is it possible to use 'for' or 'while' or the like to create</P>
<P>arbitrarilly many named class instances? Tried to do something</P>
<P>like:</P>
<P>for i in ['a', 'b', 'c', 'd']:</P>
<P>i = Counter()                #Counter being a class</P>
<P>print a.y, b.y, c.y, d.y   # y is a thing from the class e.g. self.y = 0.</P>
<P>(i.e. I'm trying to create four instances named a, b, c and d.)</P>
<P></P>
<P>This sort of thing does't work. Assume it just shoves a new 'value'</P>
<P>into the single 'pidgeon hole' named i every time.</P>
<P>Is this just a special case of the general problem of how to name</P>
<P>a sequence of 'cubby-holes', and put a specific</P>
<P>value into each one, instead of naming one cubby-hole and putting a</P>
<P>sequence of new values into it? I know how to create a sequence of pidgeon</P>
<P>hole contents but not how to create a sequence of named pidgeon holes.</P>
<P>Don't think this is bollocks; hope not.</P><p><p><br><hr size=1><a href="http://uk.yahoo.com/mail/tagline_xtra/?http://uk.docs.yahoo.com/mail_storage.html"><b><font face="Arial" size="2">With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits your needs</font></b></a><br>
--0-2096850781-1047658352=:88177--