[Tutor] Dynamic Function Assignment

Alan Gauld alan.gauld at freenet.co.uk
Fri Oct 21 10:06:55 CEST 2005


for id in ('A', 'B', 'C'):
   if segment.upper().startswith(id):

Think dictionary:

objects = {'A': a, 'B':b, 'C':c}

for id in ('A','B','C')
    objects[id].method()

I have a section within my OOP topic that specifically talks about this 
in the context of a collection of bank account objects. You might find 
it worth skimming through.

HTH,

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld




More information about the Tutor mailing list