[Tutor] newbie: help unkludge me

Rene Lopez RenX99 at gmail.com
Fri Oct 22 01:05:10 CEST 2004

Here is the code that seems a bit kludgey to me:

class blah
  def __init__(self)
      set_table = { 1: ("bob", "bill", 1, 2, 3),
                         2: ("gill", "sally", 5, 6, 7)}

      wanted = 1

      if  wanted in set_table:
      set1 = set_table[wanted]

      self.person1 = set1[0]
      self.person2 = set1[1]
      self.number1 = set1[2]
      self.number2 = set1[3]
      self.number3 = set1[4]

Is there a way to assign the info from set1 to the person/number
variables using a loop or something?   I considered trying something
like this:

myset = (self.person1, self.person2, self.number1, self.number2, self.number3)

so I could trying copying the data over with something like this:

while  x < 5: 
  myset[x-1] = set1[x-1]

but that doesn't work because I get an error saying that myset has no
instance of "person1" In other words...they don't exist yet, so they
can't be put into a list.  I hope this makes some sense, because
reading it sounds weird even to me :-)



More information about the Tutor mailing list