[Tutor] functions

Sean 'Shaleh' Perry shaleh@valinux.com
Fri, 19 Jan 2001 09:46:59 -0800 (PST)


> 
> login()
> main_menu()
> 
> def main_menu():
>   print "Commands here"
> 
> def login():
>   name = input("What is your name?")
> 
> But it is giving me the same error, something like: variably login does not
> exist. 
> What am I doing wrong?
> 

you need to declare the function before you use it.

$ python /tmp/test.py 
Traceback (innermost last):
  File "/tmp/test.py", line 3, in ?
    foo()
NameError: foo

#!/usr/bin/python

foo()

def foo():
        print "Foo"

$ python /tmp/test.py 
Foo

#!/usr/bin/python

def foo():
        print "Foo"

foo()