Behavior of mutable class variables
Terry Reedy
tjreedy at udel.edu
Wed May 9 17:49:14 EDT 2007
<tkpmep at hotmail.com> wrote in message
news:1178744257.369030.95310 at w5g2000hsg.googlegroups.com...
| Here's what I expect to happen each time simulation( ) is called: the
| class variable NStocks for the class Stock is initialized to an empty
| list,
Why would you expect that ;-)
A class statement is usually executed exactly once, as in your code.
The body of a class statement usually consists of several name bindings:
some are explicit, like your NStocks assignment statement;
some are implicit, like you __init__ function definition.
The resulting dictionary is used to create the class object, which is
mostly a wrapper around the dict created by the class statement body.
tjr
More information about the Python-list
mailing list