does lack of type declarations make Python unsafe?
Zac Jensen
listbox at cybereal.org
Sun Jun 15 18:06:14 EDT 2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sunday 15 June 2003 03:55 pm, martin z wrote:
> > You *can* test the types of the arguments yourself, inside
> > the function. But this is regarded bad practice amongst Python
> > programmers, for the above mentioned reasons.
>
> On this subject, is there a way to test not the specific type, or simply
> the protocol an object supports? String, int, etc. I want to make a
> function do one thing with a numeric-type object and a different thing with
> a string-type object.
Hm, perhaps hasattr() for the special __whatever__ attributes?
or if you know it has to be a set of types, you could do
isinstance(whatevervar, (type1, type2, type3)) etc....
- -Zac
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE+7O3YV3L7YsSif1URAm1IAJ0d2gg5mbElV8nLA98LCuTiBlgoTwCePAaP
twa6bsgApe7gucgzRMtkqE0=
=qc8k
-----END PGP SIGNATURE-----
More information about the Python-list
mailing list