do you guys help newbies??
Wojtek Walczak
gminick at hacker.pl
Wed Nov 27 14:01:34 EST 2002
Dnia Wed, 27 Nov 2002 18:56:32 GMT, Robin Munn napisał(a):
> while 1:
> try:
> a = int(raw_input('Enter your number: '))
> except ValueError:
> print "That wasn't a number."
> else:
> break
>
> This is almost exactly like the code you posted, except that the
> isdigit() test was completely unnecessary. Let int() catch your errors
> for you -- that's what exceptions are for.
You're right. Great code. Not switching from "C mode" to thinking in python
sometimes produces dozens of unnecessary lines of code ;)
--
[ ] 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