从字符串中拆分的数字不是数字

Maw*_*awg 4 python python-2.7

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

SLEEP 50我,我明白了Error: Sleep duration "50" is not numeric

我不太关心为什么,我只是想知道我如何编码以便SLEEP 50有效而SLEEP APNOEA不是.

Moh*_*uag 5

使用isdigit():

if not duration.isdigit():
    print 'Error: Sleep duration "' + duration + '" is not numeric'
Run Code Online (Sandbox Code Playgroud)

它会检查所有字符是否duration都是数字.