[Tutor] Second follow up

Dave Angel davea at davea.name
Tue Feb 26 15:57:47 CET 2013

On 02/26/2013 09:23 AM, Jack Little wrote:
> How would I go from one def statement to another? I am developing a text based rpg.
> Sent from my iPod
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

For your next thread, please try to pick a subject line that has 
something to do with what you're asking, or what you're trying to learn 

A def statement defines a function (or method).  Once it's defined, the 
compiler goes on to the next line, and if that's a def statement, it 
defines that function.

So all you need is a text editor.  Just understand that code that will 
call those functions from the top-level needs to be *after* the 
definition is complete.  Code that calls functions from inside a 
function does not need to be in any particular order.

If this isn't what you want, then try composing a ten-line sample, tell 
us what environment you're running it in, and what you hoped for, and 
what it did instead.

On the other hand, perhaps you're asking how to make indirect calls to 
functions.  A function object can be stored in a 'variable', simply by 
assigning it without using parentheses.  You can then later call that 
function by naming the object, and following the object with the 
parentheses.  Simple example follows;

def func1(name):
     print "function1, running with", name

def func2(name):
     print "function2, running with", name

funclist = []

     will call func2, and pass it "Sam" as an argument.

Normally, if you're doing this type of thing, you'd be using methods, 
not functions, but I'm not going to introduce classes unless you're 
already familiar with them.


More information about the Tutor mailing list