Is there a way to 'mask out' inherited methods?
Fernando Pérez
fperez528 at yahoo.com
Thu May 2 19:03:35 EDT 2002
Ralf Juengling wrote:
>
> Hi,
>
> I'm fiddling around with some new 2.2.-features. I want to
> inherit from a builtin-type but want to use only a subset
> of its functionality:
Simple example:
In [13]: class mystr(str):
....: def __str__(self):
....: return '<special '+ self + '> '
....: def __meaningless(*args,**kw):
....: raise NotImplementedError,'feature meaningless'
....: __hash__ = __ne__ = __meaningless
....:
In [14]: s=mystr('hi')
In [15]: s
Out[15]: 'hi'
In [16]: print s
<special hi>
In [17]: s.__hash__
-------> s.__hash__ ()
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
?
? in __meaningless(*args=('hi',), **kw={})
NotImplementedError: feature meaningless
cheers,
f.
More information about the Python-list
mailing list