Alan Gauld wrote: > But that's considered bad practice, it's better to put the > valid errors only in the except line like this: > > try: > print float(input)*12 > except TypeError, ValueError: > print False
Careful, you need parens around the tuple of errors, otherwise this catches only TypeErrors and assigns the TypeError instance to ValueError: >>> input = None >>> try: print float(input) * 12 ... except TypeError, ValueError: print False ... False >>> ValueError TypeError('float() argument must be a string or a number',) This is a nasty gotcha best avoided by using Python 3. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor