vendredi 29 mai 2015

Add values to a class in Python

Let's say I have the following in Python:

class Test():
    self.value1 = 1
    self.value2 = 2

def setvalue1(self, value):
    self.value1 = value

So one can set up value1 by doing:

Test.setvalue1('Hola')

or

Test.Value1 = 'Hola'

So far so good. My problem is I would like to set the values by reading them somewhere else so for instance I could have the following:

A = [['Value1','Hola'],['Value2','Adios']]

I would like to be able to run something that will do (in pseudo code):

for each in A:
    Test.each[0] = A[1]

Is this possible? Thanks so much!

Aucun commentaire:

Enregistrer un commentaire