[Numpy-discussion] classmethods for ndarray

Christopher Barker Chris.Barker@noaa....
Thu Feb 1 18:58:17 CST 2007


Sebastian Haase wrote:

> Could you explain what a possible downside of this would be !?
> It seems that if you don't need to refer to a specific "self" object
> that a class-method is what it should - is this not always right !?

Well, what these really are are alternate constructors. I don't think 
I've seen class methods used that way, but then I haven't seen them used 
much at all.

Sometimes I have wished for an overloaded constructor, i.e.:

array(SomeBuffer)

results in the same thing as

frombuffer(SomeBuffer)


but Python doesn't really "do" overloaded methods, and there are some 
times when there wouldn't be only one way the input could be interpreted.

That all being the case, it seems to make some sense to put these in as 
class methods, but :

a = numpy.ndarray.fromfile(MyFile)

does feel a bit awkward.

Wx Python handles this by having a few constructors:

wx.EmptyBitmap()
wx.BitmapFromImage()
wx.BitmapFromBuffer()
etc...

but that's kind of clunky too.

-Chris

-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov


More information about the Numpy-discussion mailing list