Listing functions in a file IN ORDER

Jean Brouwers mrjean1ATcomcastDOTnet at no.spam.net
Wed Jun 30 02:21:08 EDT 2004


Instead of listing the functions explicitly what about something like
this:

  functions = [(name, function) for name, function in globals().items()
if callable(function) and name.startswidth('do')]
  functions.sort()

  for _, function in functions:
      function(*args)


/Jean Brouwers
 ProphICy Semiconductor, Inc.


In article <mailman.290.1088537219.27577.python-list at python.org>, Ian
Sparks <Ian.Sparks at etrials.com> wrote:

> > From: Christopher T King.. 
> > Note the use of function(*args) instead of apply(function,args). 
> > apply() is deprecated starting with Python 2.3 in favor of this 'extended
> > call syntax'.
> 
> Good advice. Thanks.
> 
> > > functions = ["doTask1", "doThing", "doOther"......]
> > > 
> > > and iterate over that list?> 
> > Better yet, just have a list of the functions themselves:
> > 
> > functions = [doTask1, doThing, doOther]
> 
> Both good ideas but I want the system to do code discovery because I'm too
> dumb to remember to put things in the list.
> 
> > -----Original Message-----
> > From: Christopher T King [mailto:squirrel at WPI.EDU]
> > Sent: Tuesday, June 29, 2004 12:23 PM
> > To: python-list at python.org
> > Subject: Re: Listing functions in a file IN ORDER
> > 
> > 
> > On Tue, 29 Jun 2004, Irmen de Jong wrote:
> > 
> > > Ian Sparks wrote:
> > > 
> > > Just add a list which sums up the function names in the 
> > order you want:
> > > 
> > > functions = ["doTask1", "doThing", "doOther"......]
> > > 
> > > and iterate over that list?
> > 
> > Better yet, just have a list of the functions themselves:
> > 
> > functions = [doTask1, doThing, doOther]
> > 
> > for function in functions:
> >     function(*args)
> > 
> > Note the use of function(*args) instead of 
> > apply(function,args). apply() 
> > is deprecated starting with Python 2.3 in favor of this 
> > 'extended call 
> > syntax'.
> > 
> > -- 
> > http://mail.python.org/mailman/listinfo/python-list
> > 
>



More information about the Python-list mailing list