[Tutor] Error Message
Britt Green
britt_green@hotmail.com
Fri, 26 Jan 2001 17:30:49 -0800
Hello,
I'm new to programming and Python, and I'm getting an error message that I
can't quite seem to work around. This is my code:
import msvcrt, sys
print"""
Type a key to see its ASCII value.
Hit the space bar to end.
"""
while 1: #1 is true, so loop forever
key = msvcrt.getch()
if key != ' ':
# handle special keys; real code is second
if (key == '\000') or (key == '\xe0'):
key = msvcrt.getch()
doKeyEvent(key)
else:
doQuitEvent(key)
def doKeyEvent(key):
print ord(key)
def doQuitEvent(key):
sys.exit()
After I save this and run it, Python replies with this:
Type a key to see its ASCII value.
Hit the space bar to end.
Traceback (innermost last):
File "C:/Program Files/Python20/Code/eventloop.py", line 14, in ?
doKeyEvent(key)
NameError: There is no variable named 'doKeyEvent'
I'm stuck since doKeyEvent is a function, not a variable. Why doesn't Python
recognize it as such?
Thanks,
Britt
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com