"Andrew Zyman" wrote in message news:caprckxktozonlak8asizonkypd9y_p25fr2rkfkozxoa4bc...@mail.gmail.com...

Hello,
 i wonder what would be a proper data structure for something with the
following characteristics:

id - number,
obj[a..c] - objects of various classes

the idea is to be able to update certain fields of these objects initially
getting access to the record by ID

something like this ( not working )

### code start

class ClassA(object):
    a = ''
    b = ''
    def __init__(self):
        a= 'aa'
        b= 'ab'

class ClassB(object):
    def __init__(self):
        self.c = 'ba'
        self.d = 'bb'

def main():
    obja = ClassA
    objb = ClassB

    sets = set(obja, objb)
   contracts[1] = sets

    print('Sets ', contracts)

# with the logic like ( not working too)
        if obja.a = 'aa':
            contracts[1].obja.a = 'ABC'


 if __name__ == '__main__':
    main()


### code end

I don't really understand the question, but I would like to point out the following -

 class ClassA(object):
    a = ''
    b = ''
    def __init__(self):
        a= 'aa'
        b= 'ab'

In your __init__() function, 'a' and 'b' are not bound to anything, so they are simply local variables and will be garbage-collected when the function has completed.

Therefore any instance of ClassA() will get its values of 'a' and 'b' from the class definition - an empty string.

Frank Millman


--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to