Subclassing hidden class
Jp Calderone
exarkun at intarweb.us
Sun Feb 16 16:41:05 EST 2003
On Sun, Feb 16, 2003 at 09:11:06PM +0000, John Smith wrote:
> Is there a quick way to subclass that usually use a constructor function to
> return objects?
> For example,
>
> >>> import numarray
> >>> class myarray(numarray.array):
> pass
>
> Traceback (most recent call last):
> File "<pyshell#36>", line 1, in ?
> class myarray(numarray.array):
> TypeError: cannot create 'function' instances
>>> import numarray
>>> numarray.array
<function array at 0x82691ec>
>>> numarray.array(0)
array(0)
>>> type(array(0))
<class 'numarray.NumArray'>
>>> numarray.NumArray
<class 'numarray.NumArray'>
>>> class Foo(numarray.NumArray): pass
...
>>> Foo(0) # Uh oh!
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.2/site-packages/numarray/numarray.py", line
581, in __repr__
MAX_LINE_WIDTH, PRECISION, SUPPRESS_SMALL, ', ', 1)
File "/usr/local/lib/python2.2/site-packages/numarray/arrayprint.py", line
165, in array2string
typeless = _stdtype(a._type)
File "/usr/local/lib/python2.2/site-packages/numarray/arrayprint.py", line
149, in _stdtype
return t in [numarray.Long, numarray.Float, numarray.Complex]
File "/usr/local/lib/python2.2/site-packages/numarray/numerictypes.py",
line 102, in __cmp__
return genericTypeRank.index(self.name) -
genericTypeRank.index(other.name)
ValueError: list.index(x): x not in list
I guess this isn't very helpful, except in a very general sort of way for
looking more deeply into function/type/object relations.
Jp
--
up 8 days, 2:28, 1 user, load average: 0.17, 0.04, 0.01
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20030216/ef35f4cc/attachment.sig>
More information about the Python-list
mailing list