| Dietrich |
Aug 14th, 2006 4:46 PM |
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.
|