Assign a value to a var content in an object

Paulo da Silva p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt
Sun Oct 10 18:00:28 EDT 2021


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)



More information about the Python-list mailing list