Re: polymorphism in python
From: KefX (keflimarcusx_at_aol.comNOSPAM)
Date: 11/26/03
- Next message: Douglas Alan: "Re: Python's simplicity philosophy"
- Previous message: Paul Moore: "Re: Compressing output via pipes"
- In reply to: Roy Smith: "Re: polymorphism in python"
- Next in thread: Jay O'Connor: "Re: polymorphism in python"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 26 Nov 2003 22:52:49 GMT
>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
- Next message: Douglas Alan: "Re: Python's simplicity philosophy"
- Previous message: Paul Moore: "Re: Compressing output via pipes"
- In reply to: Roy Smith: "Re: polymorphism in python"
- Next in thread: Jay O'Connor: "Re: polymorphism in python"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|