Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Python (http://www.programmingforums.org/forum43.html)
-   -   Function without purpose? (http://www.programmingforums.org/showthread.php?t=11071)

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.

Random Spirit Aug 14th, 2006 5:00 PM

Are you making these up to test everyones python ability? :p

Good on you if you are :)

If not its good to have some threads that are actually on programming.

Arevos Aug 15th, 2006 6:47 AM

Quote:

Originally Posted by Dietrich
There's got to be something missing? All that code for such a silly outcome. Help me, so I can stop scratching my head.

It looks to be the beginnings of an event-loop system, though as you point out, it's incomplete.


All times are GMT -5. The time now is 12:50 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC