how to use variable to substitute class's variable?

Hans hansyin at gmail.com
Thu Mar 17 03:31:28 EDT 2011


I have things like:
file1:
class aaa:
    def __init__(self):
        self.variable1='a1'
        self.variable2='a2'
        self.varable3='a3'


in main proc:
import file1
b=file1.aaa()
c={'variable1':'value1','variable2':'value2','variable3':'value3'}
for key in c:
    b.key=c[key]  >>>>>>>>>>>Problem is here!!!

I hope put value1 to b.variable1, value2 to b.variable2 and value3 to
b.variable3. it does not work.  How can I do it?


By the way, I know dictionary can bind two variable together, like a 2-
dimension array.  but, if I need group 3 or more variables together,
(each group has 3 or more variables)like a 3-dimension(or higher)
array, Is there an easy way besides "class"?

Thanks a lot!!!






More information about the Python-list mailing list