need help with class of arrays which have attibutes

Rob rob at pythonemproject.com
Sat Dec 29 13:11:24 EST 2001


Thanks Emile!

Paul Dubois helped me out with this originally and I thought that his
code was broken, since a test case didn't work right.  Now I'm perplexed
since I can no longer get his code to break :)  But there is one part of
my program that definitely is hosed which uses this class, and today
I'll try to get it to work.  Here is what Paul send me:
--------------------------------
from Numeric import *
class Cond:

    x1=0
    y1=0
    lz1=0
    x2=0
    y2=0
    lz2=0
    DelX=0.0
    DelY=0.0
    DelZ=0.0

wire=map(lambda dummy: Cond(), zeros((20)))
--------------------------------------------------

In case you are wondering why I'm doing such insanity, I'm porting a C
program with chained structures.  If I don't set up some Python classes
that work the same, I'll have to change 100's of lines of code.

I will print out your code, study it, and keep it for further
reference.  Thanks a lot!  Rob.


Emile van Sebille wrote:
> 
> "Rob" <rob at pythonemproject.com> wrote in message
> news:3C2D3C2C.C9EF5AFE at pythonemproject.com...
> >
> > Hi Emile,  I've been reading the books and experimenting with different
> > kinds of classes, but it just doesn't seem possible to use an array as a
> > basis for a number of class attributes.  For example,
> > wire=conductor (i.e. class)  wire[1].x1=30  wire[2].x2=40  etc.    Rob.
> 
> import Numeric
> 
> class Test:
>     def __init__(self):
>         self.attrs = Numeric.zeros(10)
> 
>     def __repr__(self):
>         return repr(self.attrs)
> 
> t1 = Test()
> t1.attrs[2] = 1
> 
> t2 = Test()
> t2.attrs[2] = 2
> 
> print t1
> print t2
> 
> HTH,
> 
> --
> 
> Emile van Sebille
> emile at fenx.com
> 
> ---------

-- 
The Numeric Python EM Project

www.pythonemproject.com



More information about the Python-list mailing list