keyword checker - keyword.kwlist

tom at finland.com tom at finland.com
Thu May 10 11:55:26 EDT 2007


Still no go. I just can't get it right. My current script:

#!usr/bin/env python
import keyword

myInput = raw_input('Enter identifier to check >> ')
if myInput in keyword.kwlist:
     print myInput, "is keyword"

else:
     print myInput, "is not keyword"

print keyword.kwlist
print keyword.__file__

And the output:

Enter identifier to check >> else
else
is not keyword
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 
'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 
'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 
'raise', 'return', 'try', 'while', 'with', 'yield']
F:\Ohjelmat\Python25\Lib\keyword.pyc



More information about the Python-list mailing list