Pythonic way to determine if a string is a number

Tino Wildenhain tino at wildenhain.de
Mon Feb 16 02:14:33 EST 2009


Python Nutter wrote:
> Type casting seems to be the wrong way to go about this.
> 
> teststring = '15719'
> teststring.isdigit()
> returns True

Actually its instantiating not type casting and it works
by using the type's actual description of the data it
accepts. This looks pretty good approach instead of trying
to copy (incomplete as it has been shown not only digits and
. constitute a float) already implemented code.

Of course if you want to limit the range of accepted data
even more, then isdigit and friends can be used -
maybe you could time both approaches with a set of data.

Regards
Tino
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20090216/e4500a53/attachment-0001.bin>


More information about the Python-list mailing list