Function declarations

Samuel A. Falvo II kc5tja at garnet.armored.net
Mon Nov 20 13:06:22 EST 2000


On Mon, 20 Nov 2000 12:55:34 -0000, Makhno wrote:
>def Init():
>    #GUI construction code (using references to 'callback functions' below
>#define callback functions
>Init()
>#enter callback here

As I've illustrated elsewhere in this thread, you can do this:

def Init():
	# GUI construction code
	# Enter callbacks here
#define callback functions
Init()

As long as Python isn't actually *executing* the statement, you can
generally do anything you want, provided proper syntax.  Example:

def DoIt():
   print HelloWorld()	#<-- reference to undefined function at this point

def HelloWorld():	#<-- Ahh!  It's defined!
   return "Hello world!"

DoIt()

>I was hoping that Python provided a better way to manipulate callbacks in
>this manner.

Well, if you're so "hell-bent" on using callbacks (I use the term in a
good way, not derogatory), why not make *everything*, including
initialization, a callback event?  This is, for example, how the GEOS/64 and
GEOS/128 operating systems worked, and it worked astonishingly well.  I
think you'll find it'll even make your program code slightly smaller, and
more modular.  It also re-enforces the basic tenant of event-driven software
design: program code doesn't execute unless it's absolutely, positively,
100% necessary.

This would involve dyamically loading Python modules, and calling well-known
entry points, such as Init() upon initialization, ad Expunge() when unloading.

-- 
KC5TJA/6, DM13, QRP-L #1447 | Official Channel Saint, *Team Amiga*
Samuel A. Falvo II	    |
Oceanside, CA		    |



More information about the Python-list mailing list