keyword checker - keyword.kwlist
Peter Otten
__peter__ at web.de
Thu May 10 12:53:17 EDT 2007
tom at finland.com wrote:
> 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
Does
myInput = raw_input("...").strip()
# ...
work?
Your raw_input() seems to be broken and includes the trailing newline.
Peter
More information about the Python-list
mailing list