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
Post a Comment