[Tutor] Error Message

Andrew Wilkins toodles@yifan.net
Sat, 27 Jan 2001 09:44:27 +0800


Hi Britt,

In python there is no declaration of functions, you must have already
defined them before they are referenced. All you need to do is throw
those definitions to the top of your code, and you're home free.

Andrew Wilkins

> -----Original Message-----
> From: tutor-admin@python.org
> [mailto:tutor-admin@python.org]On Behalf Of
> Britt Green
> Sent: Saturday, 27 January 2001 9:31
> To: tutor@python.org
> Subject: [Tutor] Error Message
>
>
> 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
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>