[Tutor] validation

Shantanoo Mahajan shantanoo at gmail.com
Mon Aug 27 12:12:14 CEST 2007


On 27-Aug-07, at 2:20 PM, Michael wrote:

> Hi
>
> I am fairly new to Python and I wish to validate input. Such as  
> wanting
> to check and make sure that an integer is entered and the program not
> crashing when a naughty user enters a character instead. I have been
> trying to use the Type() function but I cannot work out how to  
> check the
> return value? Caomparing it to 'int' or 'str' isn't working, or  
> should I
> be using the isinstance property? I want to use raw_input and check  
> that
> it is a number. Can someone point me in the right direction?
>
> Thanks
>
> Michael

http://docs.python.org/tut/node10.html

Check section 8.3. 'Exception Handling'. You may use the example
without any modifications.

regards,
shantanoo


More information about the Tutor mailing list