#this is a better way of testing a string for float
def isFloat(s):
try:
s = float(s)
except:
return False
return True
-----Original Message-----
From: Madari, Edwin
Sent: Wednesday, August 06, 2008 10:22 PM
To: 'Wei Guo'; [email protected]
Subject: RE: A question about string and float number
type(s) == type(float())
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Wei Guo
Sent: Wednesday, August 06, 2008 9:23 PM
To: [email protected]
Subject: A question about string and float number
Hi all,
I am new of python. Could anyone help me a question as below?
Is there any function that can judge a string s is a float number or not? FOr
example, if s = '1.232' or s='1e+10', then it returns true, otherwise, it will
return false.
isdigit() in string doesn't work. float() will throw an exception and I just
need true or false as result.
Thanks a lot in advance,
Wei
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
--
http://mail.python.org/mailman/listinfo/python-list