Skip to content Skip to sidebar Skip to footer

Dynamic Class Attribute In Python?

I'm trying to write a function for a class that takes a bunch of files and adds them to the class as attributes. Right now I have some class foo, and another class bar. I want to e

Solution 1:

Save the bar-instance in a local variable:

for name in list:
    bar_value = bar(a, b, ..)
    setattr(self, name, bar_value)
    bar_value.a = 123

Post a Comment for "Dynamic Class Attribute In Python?"