Add lists to class?
mwm at mired.org
Sun Sep 4 03:11:19 CEST 2005
"BBands" <bbands at gmail.com> writes:
>> Why don't you use a real list instead?
> I am using lists... I just showed the naming schema. Here is how they
> are implemented.
> for var in range(len(self.symbols)):
> setattr(self, "_" + str(var), )
That's not the list he's talking about. And I agree with him.
Why are you setting the attreibutes "_" + str(var)? Why not just store
them in a dictionary?
>> I don't understand what
>> self.__dict__["_" + str(var)] gets you.
> It let's me access lists that aren't known at write time.
Yes, but it's ugly, makes one address space server for two different
sets of variables, and has potential for some nasty bugs. Why not just
self.lists[var] = 
Or, if you're really tied to "_", do:
self._[var] = 
Or, given that your example used increasing numeric names, just use a
which you would then reference as self._, self._, etc.
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list