[sf-lug] ThinkPython: coding problem
Alex Kleider
a_kleider at yahoo.com
Sat Oct 11 20:59:02 PDT 2008
Thanks to Jeff and Jim.
I googled python exceptions
and solved my problem using the
try:
pass
except:
pass
construct and everything works just fine.
fyi:
def int_check(n):
try:
value=int(n)
except:
return False
if type(value)==int:
return True
else:
return False
def get (check, prompt, moan):
response=raw_input(prompt)
if check(response):
return int(response)
else:
print moan
return get (check,prompt,moan)
# main body
preamble()
a=get(int_check,'Enter a: ','Problem! a must be an integer. Try again')
More information about the sf-lug
mailing list