Simple question - stock market simulation

cptn.spoon cptn.spoon at
Mon Feb 9 06:10:54 CET 2009

On Feb 9, 3:58 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> "cptn.spoon" <cptn.sp... at> writes:
> > I'm not asking for tips on the program itself, I just can't figure out
> > how to get the data structures in place. Would I use Classes or would
> > I use dictionaries? Am I completely off the mark with this?
> Typically you would use a class for the multi-fielded data structure;
> a dictionary is intended more for lookup tables where you don't know
> ahead of time what the keys will be.  Also, you'd typically use a list
> [1,2,3] rather than a tuple (1,2,3) to hold the price list.

Thanks Paul! I thought this might be the case. So how would I get the
StockMarket class instance to contain many Stock class instances and
then be able to iterate through them? I'm guessing the basic structure
would be as follows...but I think I'm wrong:

class StockMarket:

class Stock:
  def __init__(self, stockname, stockpricelist[], stockrisk,
    self.stockname = stockname
    self.stockpricelist[] = stockpricelist[]
    self.stockrisk = stockrisk
    self.stockqty = stockqty

Can you possibly point me in the right direction?


More information about the Python-list mailing list