lazy function calling?

Sam Schulenburg samschul at pacbell.net
Mon Oct 11 15:46:53 EDT 1999


In article <380202B7.ADF0E803 at GermanLloyd.org>,
  Berthold Hoellmann <hoel at GermanLloyd.org> wrote:
> Hello,
>
> I think I can remember a Python extension module, posted or announced
> here a while ago, where it was possible to make functions callable
lazy.
> This means I could call a function spam just writing spam instead of
> spam(). Was I just dreaming or is it real. And if it's real, where
can I
> get it :-)?
>
> Thanks
>
> Berthold
> --
> email: hoel at GermanLloyd.org
>    )
>   (
> C[_]  These opinions might be mine, but never those of my employer.
>




# ######################################
# DATE:         Feb 1,1999
# PROGRAMMER:   Samuel W. Schulenburg
# This function was defined at
http://starship.skyport.net/~da/parenless/
# Modifications were made by me to return function arguments
#
#//@pyfunc classfunc | wrap | This function will take a <nl>
#//                          function name and return <nl>
#//                          class variabe that instantiates<nl>
#//                          the original function<nl>
#//
#//@parm   function name    | FunctName | function name
#//@rdesc  Class function
#
########################################################################
###
def wrap(f):
    class w:
        def __init__(self,f):
            self.f = f
        def __repr__(self):
            rtn=apply(self.f)
            repr(rtn) and ""
            return rtn
        def __call__(self,*args,**kw):
            rtn = apply(self.f,args,kw)
            return(rtn)
    return w(f)

#==============END wrap ============================

The following example will show the use of wrap(f):

>>>def testwrap():
      print "This is a test of wrap\n"



>>>test = wrap(testwrap)

>>>test
   This is a test of wrap






Sent via Deja.com http://www.deja.com/
Before you buy.




More information about the Python-list mailing list