keyword checker - keyword.kwlist

Hamilton, William whamil1 at entergy.com
Thu May 10 11:25:37 EDT 2007


> From: tom at finland.com
> 
> Hi
> 
> I try to check whether a given input is keyword or not. However this
> script won't identify keyword input as a keyword. How should I modify it
> to make it work?
> 
> #!usr/bin/env python
> import keyword
> 
> input = raw_input('Enter identifier to check >> ')
> if input in keyword.kwlist:
>      print input + "is keyword"
> 
> else:
>      print input + "is not keyword"


It works fine for me.  Well, it did once I realized that 'keyword.py' was
not a good name to save the file under.  

---
-Bill Hamilton



More information about the Python-list mailing list