polymorphism w/out signatures?
Larry Bates
lbates at swamisoft.com
Thu May 6 16:27:49 EDT 2004
I use type() quite a lot. I poked around and couldn't
find where it was being deprecated. I did see that
types module is slated for deprecation. Maybe I
overlooked it?
I use:
class foo:
_stringtype=type('')
_tupletype=type(())
_listtype=type([])
def __init__(self, variable):
if type(variable) == _stringtype:
self.variable=variable # check for string type
if type(variable) in (_listtype, tupletype):
self.variable=str(variable) # check for list/tuple
.
.
.
Seems to work well. You might also want to look at
isinstance() function
Larry Bates
Syscon, Inc.
<pugnatio2 at yahoo.com> wrote in message
news:997a06e0.0405061128.6768676d at posting.google.com...
> What's the standard way to implement polymorphic behavior in a python
> method, given that method arguments can't declare their types as
> they're being passed in, and method definitions don't have signatures?
>
> For instance, if I wanted to write a method that auto-detected whether
> it was being passed a string or a tuple/list, how would I do so
> without using type() to identify the parameter's type? Using type() is
> deprecated in the documentation I've read.
>
> Thanks in advance.
More information about the Python-list
mailing list