python - Setting name of variable in a class with a function? -


i have class , want following:

class my_class:      def my_func(self, var_name):          self.var_name = 5   = my_class() a.my_func('yes') print(a.yes) 

i not sure how set class variable name using function

>>> class my_class(object): ...   def my_func(self,var_name): ...     setattr(self,var_name,5) ... >>> = my_class() >>> a.my_func('yes') >>> a.yes 5 

Comments

Popular posts from this blog

Python __call__ special method practical example -

How can I edit my VIM config so that Vim treats ".ejs" files the same as it currently treats my html files? -