Re: Confounded by Python objects

2008-07-27 Thread Steven D'Aprano
On Sun, 27 Jul 2008 20:04:27 +0200, Bruno Desthuilliers wrote: >> In general, anything that looks like this: >> >> s = '' >> for i in range(1): # or any big number >> s = s + 'another string' >> >> can be slow. Very slow. > > But this is way faster: > > s = '' > for i in range(1):

Re: Confounded by Python objects

2008-07-27 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : On Sat, 26 Jul 2008 18:54:22 +, Robert Latest wrote: 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 li

Re: Confounded by Python objects

2008-07-27 Thread Steven D'Aprano
On Sat, 26 Jul 2008 18:54:22 +, Robert Latest wrote: > 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 att

Re: Confounded by Python objects

2008-07-26 Thread Robert Latest
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 w

Re: Confounded by Python objects

2008-07-24 Thread satoru
On Jul 24, 6:10 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On Jul 24, 11:59 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > > > tip: if you're not 100% sure why you would want to put an attribute > > on the class level, don't do it. > > The reason I did it was sort of C++ish (that's where

Re: Confounded by Python objects

2008-07-24 Thread [EMAIL PROTECTED]
On Jul 24, 11:59 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > tip: if you're not 100% sure why you would want to put an attribute > on the class level, don't do it. The reason I did it was sort of C++ish (that's where I come from): I somehow wanted a list of attributes on the class level. More

Re: Confounded by Python objects

2008-07-24 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > class Channel: > name = '' > sample = [] These are class variables, not instance variables. Take them out, and ... > def __init__(self, name): > self.name = name ... add this line to the above function sel

Re: Confounded by Python objects

2008-07-24 Thread alex23
On Jul 24, 7:45 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > class Channel: > name = '' > sample = [] > > def __init__(self, name): > self.name = name > > def append(self, time, value): > self.sample.append((time, value)) > self.diag() > > def dia

Re: Confounded by Python objects

2008-07-24 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: take a look at the code snippet below. What I want to do is initialize two separate Channel objects and put some data in them. However, although two different objects are in fact created (as can be seen from the different names they spit out with the "diag()" method), th

Confounded by Python objects

2008-07-24 Thread [EMAIL PROTECTED]
Hello group, take a look at the code snippet below. What I want to do is initialize two separate Channel objects and put some data in them. However, although two different objects are in fact created (as can be seen from the different names they spit out with the "diag()" method), the data in the