Apply and map function

Michael Chermside mcherm at destiny.com
Thu Jul 18 16:00:57 EDT 2002


> I want to implement the apply or map function into the following code:
> 
>         initmethods = InitMethods()
>         methods = {
>             'SiteNav_OpenTreeLevel': initmethods.init_opentreelevel(),
>             'SiteNav_LinkTreeItem': initmethods.init_linktreeitem(),
>             'SiteNav_ActiveTreeItem': initmethods.init_activetreeitem(),
>             'SiteNav_CloseTreeLevel': initmethods.init_closetreelevel(),
>             'local_css': initmethods.init_localcss()
>             }
>         for (methodname,method) in methods.items():
>             self.createDTMLMethod(methodname, '',method)
> 

I'm not certain I understand what you want, but is this it?

# Untested code
some_method_name_here(self):
     initmethods = InitMethods()
     methods = {
         'SiteNav_OpenTreeLevel': initmethods.init_opentreelevel(),
         'SiteNav_LinkTreeItem': initmethods.init_linktreeitem(),
         'SiteNav_ActiveTreeItem': initmethods.init_activetreeitem(),
         'SiteNav_CloseTreeLevel': initmethods.init_closetreelevel(),
         'local_css': initmethods.init_localcss(),
         }
     def createDTMLMethod( (methodname, method) ):
         self.createDTMLMethod(methodname, '', method)
     map( createDTMLMethod, methods.items() )

The only trick I used here is to write a function that expected the pair 
of arguments methods.items() provides (instead of two separate items). 
If that wasn't your problem, try explaining your question again.

-- Michael Chermside








More information about the Python-list mailing list