Re: Assign a value to a var content in an object

2021-10-11 Thread Chris Angelico
On Tue, Oct 12, 2021 at 9:03 AM Paulo da Silva wrote: > > Hello! > > Is there a better way of doing this? > Why didn't setattr (as commented) work? > > Thanks for an help/comments. > > class C: > def f(self,v): > #setattr(self,n,v) > self.__dict__['n']=v > > c=C() > c.f(3) > pr

Re: Assign a value to a var content in an object

2021-10-11 Thread Paulo da Silva
Às 23:28 de 10/10/21, Stefan Ram escreveu: > Paulo da Silva 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

Assign a value to a var content in an object

2021-10-11 Thread Paulo da Silva
Hello! Is there a better way of doing this? Why didn't setattr (as commented) work? Thanks for an help/comments. class C: def f(self,v): #setattr(self,n,v) self.__dict__['n']=v c=C() c.f(3) print(c.n) -- https://mail.python.org/mailman/listinfo/python-list