test if a subclass inherits a superclass method
dreyemi at gmail.com
Sat Sep 10 14:05:08 CEST 2011
On Sat, Sep 10, 2011 at 12:58 PM, Kayode Odeyemi <dreyemi at gmail.com> wrote:
> I'm testing Python's class abstractness and inheritance. Since interface
> doesn't exist, I will
> like to test how to have access to a superclass method from a subclass
> without necessary
> invoking or overriding the superclass method in its subclass.
> >>> class Equipment(object):
> ... def fault():
> ... return "fault"
> >>> Equipment().__class__
> <class '__main__.Equipment'>
> >>> class Vehicle(Equipment):
> ... # Find out here if Vehicle has access to fault
> I want to know whether Vehicle has access to Equipment's fault() method.
> Just want to know if it's there(that a vehicle can also develop a fault).
> I know I can override it, but I want to know if I can use it directly
> without overriding it.
OK! I figured it out like this:
>>> v = Vehicle()
['__class__', '__delattr__', '__dict__', '__doc__', '__format__',
e__', '__hash__', '__init__', '__module__', '__new__', '__reduce__',
x__', '__repr__', '__setattr__', '__sizeof__', '__str__',
> Odeyemi 'Kayode O.
> http://www.sinati.com. t: @charyorde
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list