Simple questions on use of objects (probably faq)
brian at rkspeed-rugby.dk
Wed Mar 8 13:19:20 CET 2006
Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
Thanks for the answers. They are very useful.
> self.args = (x, y, z) # save a copy of the arguments
As always python makes it easy.
Actually I wanted to get the maximum of attributes of several
instances. List comprehension is the answer.
> method. Do this instead:
I always get confused by extend and append.
> this is wasteful. Just call the function at the end, after collecting all
> the values:
> for index, value in enumerate(ys[:-1]):
> yz.append(ys[index+1] - value)
I will need to study enumerate a bit.
> By the way, don't be shy about using more meaningful names for variables.
> ys and yz are terribly similar, and is a bug waiting to happen.
I know, and in the real code I use better names.
> You can't use continue in there, it isn't a null-op. Perhaps you wanted
> How about, before trying to invent short cuts, you actually learn some of
> the Python syntax? The [x:y] syntax already has a meaning to Python,
> just not what you want.
Perhaps it is not the same, but quite close. In matlab .* is
element-by-element multiplication. I was thinking about a .-
operator. wouldn't that make sense here?
> Also, while everything in Python is an object, you don't *have* to use
> object oriented techniques.
In the real problem the class is:
and I thought it would make sense to store this a objects. Otherwise I
would need to store each stream as a list is refer their indexes.
Brian (remove the sport for mail)
More information about the Python-list