Well Im not sure what you are tying to achieve here, but there might be a couple things off here ....
class Person(object):
def __init__(self):
self.attributes = []
This defines a class object from which you can create objects that contain attributes
as we can see from the __init__
or constructor as its called in some other languages.
but you have
Person.attributes.append(local_var)
here Person
is a class object it really doesn't have the attributes that where define since does are only for objects created from this class ...
you can create a new person and add the appropriate attributes to them.
>>> me = Person()
>>> me.attributes.append('humble')
Second we really shouldn't access attributes directly since anything could be appended to a list, including duplicate attributes.
so why not simply add a function that adds attributes.
class Person(object):
def __init__(self):
self._attributes = [] # note any variable starting with _ is meant to be private
def add_attribute(attribute):
if attribute not in self._attributes:
self._attributes.append(attribute)
if performance is a concern we can use a set()
instead of []
since it won't allow duplicate entries and really fast checks for any lookups the downside is that the values have to be hash-able ie strings or ints or other simple data types ...