[Tutor] Order of functions

Rob Andrews rob@jam.rr.com
Tue, 10 Jul 2001 08:53:50 -0500


# This is addsem.py

addsem()

def addsem():
    total=2+2
    print total

# When run from the command line (DOS prompt for some), the following is
returned:

D:\Python21>python addsem.py
Traceback (most recent call last):
  File "addsem.py", line 1, in ?
    addsem()
NameError: name 'addsem' is not defined


# This is addem.py

def addem():
    total=2+2
    print total

addem()

#This is the more desirable output generated:

D:\Python21>python addem.py
4

You asked specifically about classes, so this might not answer your
question. But in these non-class-oriented scripts, the function must be
defined before calling it.

Rob


Useless Python:
Aw, heck, we love you!
http://www.lowerstandard.com/python/
 -----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Praveen Pathiyil
Sent: Tuesday, July 10, 2001 8:31 AM
To: tutor@python.org
Subject: [Tutor] Order of functions


Hi,

        Is the order of functions important in python ?
        Suppose that i have a class X. If i have functions a, b,c and if 'a'
calls 'b', is it necessaruy to define 'b' before 'a' or before 'b' is being
called.

Praveen.