do you guys help newbies??
Wojtek Walczak
gminick at hacker.pl
Wed Nov 27 14:01:34 EST 2002
Dnia Wed, 27 Nov 2002 16:20:13 -0000, Simon Brunning napisał(a):
> See <http://www.linuxgazette.com/issue83/evans.html>.
Thanks! Great article. Now the code looks like this:
---
import sys
def prompt():
return raw_input("Put a digit here: ")
try:
a = prompt()
while 1:
a = a.replace(' ','')
if a[0] == '-' and a[1:].isdigit():
a = int(a)
break
elif not a.isdigit():
a = prompt()
else:
a = int(a)
break
except:
print sys.exc_info()[1]
sys.exit()
---
...and it's not too bad example of reliable code getting input from users ;)
--
[ ] gminick (at) underground.org.pl http://gminick.linuxsecurity.pl/ [ ]
[ "Po prostu lubie poranna samotnosc, bo wtedy kawa smakuje najlepiej." ]
More information about the Python-list
mailing list