check on numerical value?

Harvey Thomas hst at empolis.co.uk
Thu Jun 6 14:57:11 CEST 2002


Henk wrote:
> 
> Is there any way to discover when a value is numerical or not in
> Python? I want a check in my code on a given value. If somebody enters
> or gives me something like "akjlvqùirq" this is surely not a numerical
> value.
> 
> Thanks,
> 
> Henk
> -- 

>>> while 1:
...     try:
...         i = int(raw_input('Please enter an integer '))
...         break
...     except ValueError: pass
...
Please enter an integer r
Please enter an integer 78
>>>

Use float instead of int if appropriate

Harvey

_____________________________________________________________________
This message has been checked for all known viruses by the MessageLabs Virus Scanning Service.





More information about the Python-list mailing list