polymorphism in python
KefX
keflimarcusx at aol.comNOSPAM
Wed Nov 26 17:52:49 EST 2003
>f your intent is that you could call foo(4) or foo('4'), you could just
>write:
>
>def foo (x):
> theRealX = int (x)
>
>or you could maybe even do:
>
>def foo (x):
> if type(x) == StringType:
> do string stuff
> else:
> do integer stuff
>
>but if you're trying to do either of the above, I suspect you're trying
>to write C++ in Python (which is as bad, if not worse, as trying to
>write Fortran in Python).
The second example should use the expression:
isinstance(x, str)
and not this:
type(x) == StringType
But as you said, it's best to avoid doing it at all ;)
- Kef
More information about the Python-list
mailing list