Advice Criticism on Python App

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Thu Mar 25 06:10:06 CET 2010


On Wed, 24 Mar 2010 21:14:23 -0700, Tim Roberts wrote:

> Jimbo <nilly16 at yahoo.com> wrote:
>>
>>class stock:
>>    code             = ""
>>    purchasePrice    = 0
>>    purchaseQuantity = 0
>>    price            = []  # list of recent prices 
>>    recentBid        = []  # list of recent bids for stock
>>    recentOffer      = []  # list of recent offers for stock
>>    stockVol         = []  # list of stock quantity available on market
> 
> Using lists as class variables is a very good way to create very
> surprising bugs.  Consider the following:
[snip]


Don't you think that the class attributes are *supposed* to be shared by 
all instances? In that case the behaviour you show is not a bug at all.


-- 
Steven



More information about the Python-list mailing list