typechecks: just say no! (was Re: Determining Types)
Fredrik Lundh
fredrik at pythonware.com
Tue Sep 4 03:43:33 EDT 2001
Skip Montanaro wrote:
> I suppose it might be the way you've written it, but I don't actually call
> an extra function to perform the comparison. I just code the test inline:
>
> if type(var) is not types.StringType:
> var = str(var)
oh, that's lame ;-)
str does the same thing, but in C. from the documentation:
str(object)
Return a string containing a nicely printable representation
of an object. For strings, this returns the string itself.
same goes for int(), float(), long(), and tuple() (but not list())
</F>
<!-- (the eff-bot guide to) the python standard library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list