How to create a method that can make class variables in python? -


let's want make object has method adds variables function. example lets have object called obj. when write obj.create_var("sample_variable"), can call obj.sample_variable. want method takes name of variable parameter , creates variable on object. how write method?

def createvar(self, name, value):     setattr(classname, name, value) 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -