Confounded by Python objects

Robert Latest boblatest at
Sat Jul 26 20:54:22 CEST 2008

satoru wrote:

> As to "sample", it never get assigned to and when you say "append" the
> class variable is changed in place.
> hope my explaination helps.

Sure does, thanks a lot.

Here's an interesting side note: After fixing my "Channel" thingy the
whole project behaved as expected. But there was an interesting hitch.
The main part revolves around another class, "Sequence", which has a
list of Channels as attribute. I was curious about the performance of my
script, because eventually this construct is supposed to handle
megabytes of data. So I wrote a simple loop that creates a new Sequence,
fills all the Channels with data, and repeats.

Interistingly, the first couple of dozens iterations went satisfactorily
quickly (took about 1 second total), but after a hundred or so times it
got really slow -- like a couple of seconds per iteration.

Playing around with the code, not really knowing what to do, I found
that in the "Sequence" class I had again erroneously declared a class-level
attribute -- rather harmlessly, just a string, that got assigned to once in each
iteration on object creation. 

After I had deleted that, the loop went blindingly fast without slowing

What's the mechanics behind this behavior?


More information about the Python-list mailing list