Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number split from a string is not numeric

duration = inputScriptLine.split(' ', 1)[1]
if type(duration) == str:
    print '    Error: Sleep duration "' + duration + '" is not numeric'

given SLEEP 50, I get Error: Sleep duration "50" is not numeric

I am not too concerned as to why, I just want to know how I can code so that SLEEP 50 is valid and SLEEP APNOEA is not.

like image 559
Mawg says reinstate Monica Avatar asked Dec 14 '22 08:12

Mawg says reinstate Monica


1 Answers

Use isdigit():

if not duration.isdigit():
    print 'Error: Sleep duration "' + duration + '" is not numeric'

It would check whether all characters in duration are digits or not.

like image 94
Mohammed Aouf Zouag Avatar answered Dec 21 '22 22:12

Mohammed Aouf Zouag