On 28/08/12 21:24, Wayne Werner wrote:
On Mon, 27 Aug 2012, Richard D. Moores wrote:
What the best way to test if something's an integer?try: whatever_you_want(supposed_integer) except ValueError: print("Oops, that wasn't an integer! Please try again") That's usually the best way...
Actually, that's close to the worst way, since you take a nice, useful exception which prints a traceback showing exactly what went wrong, and replace it with a pointless, silly message which can't be caught by the caller. Trying again may be impossible, or inappropriate, and certainly isn't up to the function to make that decision, that's up to the caller to decide what is the appropriate response to invalid data. -- Steven _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
