View Single Post
Old Aug 14th, 2006, 3:46 PM   #1
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Function without purpose?

Here is another function from the net that seems to be imcomplete as far as its purpose goes:
#global dict to store targets
targets={}

#the target class
class Target:
    def __init__(self, name='', dependencies=[], fn=None):
        self.name = name
        self.dependencies = dependencies
        self.fn = fn
        self.done = False
        self.success = False

    def run(self):
        if (not self.done):
            self.success = self.fn(self)
            self.done = True
        return self.success

#the target decorator function
def target(name, dependencies=[]):
    def decorator(f):
        mytarget = Target(name, dependencies, f)
        targets[name] = mytarget
        return f
    return decorator

#implementing the decorator
@target('my_target')
def MyFunction(target):
    print "hello world! from", target.name
    return True

targets['my_target'].run()    # hello world! from my_target
There's got to be something missing? All that code for such a silly outcome. Help me, so I can stop scratching my head.
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote