The old "function order definition" problem nails a newbie every time. It's worth a note that this is why you always see this idiom in Python:
def fun1(): print 'Function 1' def main (): fun1 () fun2 () def fun2(): print 'Function 2' if __name__ == '__main__' : main () See the last two lines? Always put those at the END of your Python code so you will not have to worry about what order your function definitions are declared in. As an added feature, Python will NOT run main() if this module is imported by another module. This way you can make scripts that will both run as immediate programs or can be modules to other scripts. The function name main() is not special. You can put any code after the if __name__... Howver the variable __name__ is special in Python. Python only defines __name__ as '__main__' when the script is being run immediately from the interpreter; otherwise, if this module is imported then __name__ is defined as the name of the module. Noah ----- Original Message ----- From: "Paul Osman" <[EMAIL PROTECTED]> To: "Jose Guevarra" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Thursday, April 04, 2002 9:52 PM Subject: Re: pissed newbie: why wont this function work > Jose, > > the answer to your problem is very simple. > ... > Reason this wasn't working is that in python, you have to define your > functions *before* you call them. > > Cheers, > -Paul > > Jose Guevarra wrote: > > >Hi, > > > > I was just trying to make a simple range function that works w/ decimal > >numbers instead of just integers. Im new to python and I don't know if > >one already exists, but that's besides the point. > > > >Im following the examples and syntax that Ive seen but it keeps coming > >up w/ a "name error". It runs fine w/ not defined as a function > > > >Here's the script > >#! /bin/python > > > >a = frange(0, 13.45, 1.5) > >print a > > > > > >def frange(xo, xn, incrmt): > > b = [] > > sum = xo > > > > while(sum < xn): > > sum = sum + incrmt > > b.append(sum) > > > > > > return b > > > >what's the problem here? > >thanx _______________________________________________ ActivePython mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs