How do I access a main frunction from an import module?

Steve steve at ferg.org
Fri Nov 24 13:30:16 EST 2006


This is an interesting question.  It almost looks like a case of
event-driven programming, where main is the plug-in and abc is the
framework.
http://eventdrivenpgm.sourceforge.net/

So how about something like this:

################## abc.py ####################

#------------------------------------------------------------
# an "abstract" function.
# It should be over-ridden in the calling program
#------------------------------------------------------------
def m():
	raise AssertionError("You should have over-ridden abstract function
m()")

def a():
    m()
    return None


########### main.py ####################
import abc  # "instantiate" the framework

# define our our "concrete" function m
def m():
    print 'something'
    return None

#-----------------------------------------------
# override the "abstract" function abc.m()
# with our own "concrete" function m().
# Comment out this line and see what happens.
#-----------------------------------------------
abc.m = m

# invoke the a() function in the abc framework
abc.a()

#################################################




More information about the Python-list mailing list