Re: test if a subclass inherits a superclass method

2011-09-10 Thread Littlefield, Tyler

On 9/10/2011 5:58 AM, Kayode Odeyemi wrote:

Hello,

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 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.


Perhaps this helps:
http://stackoverflow.com/questions/610883/how-to-know-if-an-object-has-an-attribute-in-python


--
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde




--

Take care,
Ty
Web: http://tds-solutions.net
The Aspen project: a light-weight barebones mud engine
http://code.google.com/p/aspenmud

Sent from my toaster.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: test if a subclass inherits a superclass method

2011-09-10 Thread Kayode Odeyemi
On Sat, Sep 10, 2011 at 12:58 PM, Kayode Odeyemi  wrote:

> Hello,
>
> 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 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()
>>> dir(v)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__',
'__getattribut
e__', '__hash__', '__init__', '__module__', '__new__', '__reduce__',
'__reduce_e
x__', '__repr__', '__setattr__', '__sizeof__', '__str__',
'__subclasshook__', '_
_weakref__', 'fault']

Cool stuff.

-- 
> Odeyemi 'Kayode O.
> http://www.sinati.com. t: @charyorde
>
>


-- 
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde
-- 
http://mail.python.org/mailman/listinfo/python-list


test if a subclass inherits a superclass method

2011-09-10 Thread Kayode Odeyemi
Hello,

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 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.
-- 
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde
-- 
http://mail.python.org/mailman/listinfo/python-list