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

android - questions about switching from C2DM to GCM -

c++ - Qt setGeometry: Unable to set geometry -

batch file - How to extract all multi-volume RAR archives from subfolders of a folder? -