Add lists to class?

Michael Hoffman cam.ac.uk at mh391.invalid
Fri Sep 2 13:31:40 EDT 2005


BBands wrote:

> I start with a text file of ticker symbols. I read each symbol and
> stick it in a list, retrieve the data for it from MySQL, do a trivial
> smoothing and pass the data to a modeling routine. I read the tickers
> into a list, self.symbols.

OK...

 > Then for each ticker I create a list,
> self._0, self._1, ...

That's not a list. That's a bunch of attributes.

> I end up with data I can access
> with self.__dict__["_" + str(var)] and a matching symbol which I can
> access self.symbols[var].  Ideas for a better approach gladly accepted.

Why don't you use a real list instead? I don't understand what 
self.__dict__["_" + str(var)] gets you.

self.symbols = ["IBM", "MSFT", "SCOX"]
self.values = [99, 100, 0.25]
self.smooth_values = [100, 100, 0]

or you could use a dict:

self.values = dict(IBM=99, MSFT=100, SCOX=0.25)
-- 
Michael Hoffman



More information about the Python-list mailing list