Re: Inherit from array

2006-04-27 Thread Scott David Daniels
bruno at modulix wrote: > TG wrote: >> Hmm ... I'm definitely not a python wizard, but it seems to be quite a >> special case that breaks the rules ... > > Yes and no. The primary use case for __new__ was to allow subclassing of > immutable types. array.array is not immutable, but it's still a sp

Re: Inherit from array

2006-04-27 Thread bruno at modulix
TG wrote: > Hmm ... I'm definitely not a python wizard, but it seems to be quite a > special case that breaks the rules ... Yes and no. The primary use case for __new__ was to allow subclassing of immutable types. array.array is not immutable, but it's still a special case, in that it enforce typ

Re: Inherit from array

2006-04-27 Thread TG
Hmm ... I'm definitely not a python wizard, but it seems to be quite a special case that breaks the rules ... unpythonic, isn't it ? Has anyone seen a PEP on this subject ? Just in case a troll reads this message : i'm not saying python sucks or has huge design flaws here ... -- http://mail.pyt

Re: Inherit from array

2006-04-26 Thread bruno at modulix
Sion Arrowsmith wrote: > TG <[EMAIL PROTECTED]> wrote [something like]: >>from array import array > >>class Vector(array): >> def __init__(self,size): >> array.__init__('f') >> >>v = Vector('c') >>print repr(v) >> >>will output : >> >>array('c') > > > Is this a case of new-sytle classes

Re: Inherit from array

2006-04-26 Thread Sion Arrowsmith
TG <[EMAIL PROTECTED]> wrote [something like]: >from array import array >class Vector(array): >def __init__(self,size): >array.__init__('f') > >v = Vector('c') >print repr(v) > >will output : > >array('c') Is this a case of new-sytle classes being confusing? Because I'm certainly confu

Re: Inherit from array

2006-04-26 Thread bruno at modulix
Philippe Martin wrote: > > bruno at modulix wrote: >>TG wrote: >> >>>Hi there. >>> >>>I'm trying to create a simple class called Vector which inherit from >>>array. >> >>Which array ? > > I think he did > > fr

Re: Inherit from array

2006-04-26 Thread bruno at modulix
TG wrote: > Obviously, there is something I didn't catch in python's inheritance. Nope. Obviously, array.array doesn't respect the usual rules. > from array import array > class Vector(array): > def __init__(self,size): > print self.typecode > array.__init__(self,'f') > > >>

Re: Inherit from array

2006-04-26 Thread TG
Obviously, there is something I didn't catch in python's inheritance. from array import array class Vector(array): def __init__(self,size): print self.typecode array.__init__(self,'f') >>> v = Vector('c') c Here, it says the typecode is 'c' - I thought such an information was

Re: Inherit from array

2006-04-26 Thread Philippe Martin
I think he did from array import * Philippe bruno at modulix wrote: > TG wrote: >> Hi there. >> >> I'm trying to create a simple class called Vector which inherit from >> array. > > Which array ? > > [EMAIL PROTECTED] ~ $ python > Python

Re: Inherit from array

2006-04-26 Thread TG
from array import array class Vector(array): def __init__(self,size): print "pouet" array.__init__('f') print "pouet" v = Vector('c') print repr(v) will output : pouet pouet array('c') -- http://mail.python.org/mailman/listinfo/python-list

Re: Inherit from array

2006-04-26 Thread bruno at modulix
TG wrote: > Hi there. > > I'm trying to create a simple class called Vector which inherit from > array. Which array ? [EMAIL PROTECTED] ~ $ python Python 2.4.2 (#1, Feb 9 2006, 02:40:32) [GCC 3.4.5 (Gentoo 3.4.5, ssp-3.4.5-1.0, pie-8.7.9)] on linux2 Type "help"

Inherit from array

2006-04-26 Thread TG
Hi there. I'm trying to create a simple class called Vector which inherit from array. class Vector(array): def __init__(self,length): """initialize a vector of random floats of size length. floats are in interval [0;1]""" array.__init_