Às 23:28 de 10/10/21, Stefan Ram escreveu: > Paulo da Silva <p_d_a_s_i_l_v_a...@nonetnoaddress.pt> writes: >> class C: >> def f(self,v): >> #setattr(self,n,v) >> self.__dict__['n']=v > >> Why didn't setattr (as commented) work? > > Because the name n has not been initialized to a suitable > value in the function f. You could write > > setattr( self, "n", v ) Ah, OK - I missed the "" around n! :-( > > , but if you want this, > > self.n = v > > would be better. Of course :-) But that's not the purpose. This is just a toy example.
Thanks. -- https://mail.python.org/mailman/listinfo/python-list