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

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -