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

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

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