How best to reference parameters.

Ron Adam rrr at ronadam.com
Wed Oct 26 17:43:57 EDT 2005



David Poundall wrote:
> Sadly Ron,  c_y can only see index and showall in your example.

Well, don't give up!  The approach is sound and I did say it was 
untested.  Here's a tested version with a few corrections. :-)

Cheers,
    Ron




class Pump(object):
     def __init__(self, name, ptype, number):
         self.status = 0
         self.name = name
         self.ptype = ptype
         self.number = number

class C_Y(object):
      def __init__(self, plist):
           index = []
           for p in plist:
               self.__dict__[p[0]] = Pump(*p)
               index.append(p[0])
           self.index = index
      def showall(self):
           out = []
           for item in self.index:
                out.append( "%s: %r, %r, %r\n"
                            % ( self.__dict__[item].name,
                                self.__dict__[item].status,
                                self.__dict__[item].ptype,
                                self.__dict__[item].number ) )
           return  ''.join(out)


pumplist = [ ('p1', 'ob1', 0),
              ('p2', 'ob1', 1),
              ('p3', 'ob1', 2) ]

c_y = C_Y(pumplist)

print c_y.p1.name
print c_y.p1.status
print c_y.p1.ptype
print c_y.p1.number
print

c_y.p1.status = 1
print c_y.p1.status
print

print c_y.showall()




More information about the Python-list mailing list