[Tutor] converting string to a number

nik my.mailing.lists at noos.fr
Thu Sep 2 13:07:07 CEST 2004


hi,

I have a string that could either be a number or text, and I'd like to 
test which it is.

If I do

try:
	number = string.atof(str)
	# do my number stuff
except: 
	text = str
	# do my string stuff

then it's using the exception handling like an if statement. This feels kinda wrong (hacky or lazy).

Is it, or is it an acceptable method in python?


nik






More information about the Tutor mailing list