polymorphism w/out signatures?

Robert Brewer fumanchu at amor.org
Thu May 6 16:21:38 EDT 2004


Roy Smith wrote:
> you could define nuke something like:
> 
> def nuke (lang):
>    if isinstance (lang, types.TupleType):
>       for oneLanguage in lang:
>          nuke (oneLanguage)
>    else:
>       whatever

In Python 2.2+, you can usually avoid importing the 'types' module, and
just use the builtin constructors:

http://www.python.org/2.2.3/descrintro.html#factories

def nuke(lang):
    if isinstance(lang, tuple):    # instead of types.TupleType
        for oneLanguage in lang:
            nuke(oneLanguage)
    else:
        whatever


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org




More information about the Python-list mailing list