473,794 Members | 3,056 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

keyword checker - keyword.kwlist

tom
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('Ente r identifier to check >')
if input in keyword.kwlist:
print input + "is keyword"

else:
print input + "is not keyword"
May 10 '07 #1
6 3349
On 10 Mag, 15:38, t...@finland.co m wrote:
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('Ente r identifier to check >')
if input in keyword.kwlist:
print input + "is keyword"

else:
print input + "is not keyword"
Hmm... I tried, and identify it.
Try to change the 'input' variable name with other...

May 10 '07 #2
tom
>
Hmm... I tried, and identify it.
Try to change the 'input' variable name with other...
Changed input variable to myInput, but the result is still the same.

for example, 'else' isn't identified as a keyword by the script though
it exists in keyword.kwlist.
May 10 '07 #3
On Thu, 10 May 2007 13:38:40 +0000, tom wrote:
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?
It works for me.

Try printing keyword.__file_ _ to make sure you are importing the right
file. Also try printing keyword.kwlist.

--
Steven.

May 10 '07 #4
In article <_e************ ***@read3.inet. fi>, <to*@finland.co mwrote:
[ ... ]
>Try to change the 'input' variable name with other...
Changed input variable to myInput, but the result is still the same.
That was good advice, but isn't going to help here. Because "input"
isn't a keyword, it's a builtin. If you want to check builtins as
well as keywords, you need
>>if myInput in keyword.kwlist + dir(__builtins_ _):
(Although obviously you'd pre-build that list.)
>for example, 'else' isn't identified as a keyword by the script though
it exists in keyword.kwlist.
?
>>def check():
.... input = raw_input('Ente r identifier to check >')
.... if input in keyword.kwlist:
.... print input, "is keyword"
.... else:
.... print input, "is not keyword"
....
Enter identifier to check >input
input is not keyword
>>check()
Enter identifier to check >else
else is keyword
>>>
--
\S -- si***@chiark.gr eenend.org.uk -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
May 10 '07 #5
tom
Still no go. I just can't get it right. My current script:

#!usr/bin/env python
import keyword

myInput = raw_input('Ente r 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\Pyt hon25\Lib\keywo rd.pyc
May 10 '07 #6
to*@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('Ente r 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\Pyt hon25\Lib\keywo rd.pyc
Does

myInput = raw_input("..." ).strip()
# ...

work?

Your raw_input() seems to be broken and includes the trailing newline.

Peter
May 10 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3517
by: Hank Reed | last post by:
I am trying to use the spell checker on an unbound control in Access 2000. I run the checker in the AfterUpdate event of the control. After the spell checker is done, I get the following message: The Macro or Function set to the BeforeUpdate or ValidationRule Property for this field is preventing MS Access from saving the data in the field. I have no validation code or mask and no code in the Before Update event.
8
2115
by: Joe | last post by:
Hello All: Does anyone know of a spell checker that works with .NET? Any options will be welcome. TIA, -- Joe
0
1954
by: Pager O Rama | last post by:
Hi, R U BLOCKED ON MSN Messenger By Your Friend,then What are you waiting for.Visit one of the link below to find out who has blocked you in his/her friend list. http://www.hotmailpk.com/ http://www.hotmailpk.com/msnblockchecker/ http://www.hotmailpk.com/msn-block-checker/
5
7191
by: rob | last post by:
Does anyone know of a duplicate file checker project in C#? Couldn't locate anything on CodeProject or SourceForge. Has anyone here considered writing one?
13
2690
by: kolmogolov | last post by:
/* Hi, I have removed things irrelevant to reproducing the problem. What's wrong with my code? Thanks in advance for any hint! 1166425362 */ #include <stdio.h> #include <stdlib.h> #include <string.h>
4
6254
by: sweetguy1only | last post by:
Hi all, I am a MS Access developer using VB 6 (yes, I know it is a bit old). The problem I am having is, I have a software that allows my customers to put in the information of their clients. A client of one of my customer has a last name of "Cotten". Whenever they put in the last name as "Cotten", the spell checker automatically converts it to "Cotton". The thing is, I am sending them the run-time version of Access. Many of my...
6
10833
by: Neil | last post by:
Is there way to have control over the MS-Access spell checking (besides just launching it)? We want to tell it to check all records, but skip certain fields (or, alternatively, ONLY check certain fields). Is that possible? Alternatively, if that's not, we noticed that the spell checker skips fields that are disabled. So one could disable the fields to be skipped; run the spell checker; and then re-enable those fields when done. But how...
9
6271
by: ARC | last post by:
Hello all, I developed a tool a year or so ago for adding your own spell-checker to an access application. This is mainly for those using the runtime, as you can't distribute the spell-checker ability. After many complaints from my runtime customers, I decided to develop my own, which was a good challenge. I just wanted to give something back to the board / fellow access developers and offer the source for free. This board has been,...
3
4025
by: Mike | last post by:
I have an app running at a client where, when the spell checker is supposed to run, it reports "Can't start spell checker because it is not installed". I have never had this before - it works fine at other user sites and on my development setup. The app runs on MS Access 2002 runtime. Is there maybe an incompatibility with Office 2007?
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10435
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9037
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6779
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.