Coder Social home page Coder Social logo

Add decorator definitions about fyrd HOT 3 CLOSED

mikedacre avatar mikedacre commented on May 26, 2024
Add decorator definitions

from fyrd.

Comments (3)

MikeDacre avatar MikeDacre commented on May 26, 2024

This can be done with a three layer decorator:

>>> class Job:
... 
...     def __init__(self, command, args, kwds, profile):
...         self.command = command
...         self.args = args
...         self.kwds = kwds
...         self.profile = profile
... 
...     def submit(self):
...         self.command(*self.args, **self.kwds)
... 
...     def __repr__(self):
...         return "Im a Job, and my name is {0}".format(self.profile)
... 
>>> def make_job(profile=None):
...     def deco(func):
...         def wrapper(*args, **kwds):
...             job = Job(func, args, kwds, profile)
...             return job
...         return wrapper
...     return deco
... 
>>> @make_job(profile='bob')
... def hi(instr):
...     print('Hi {0}!'.format(instr))
... 
>>> j = hi('vincent')
>>> j
Im a Job, and my name is bob
>>> j.submit()
Hi vincent!

This will allow people to make any random function a job.

from fyrd.

MikeDacre avatar MikeDacre commented on May 26, 2024

Now implemented and functional in 0.6.2

from fyrd.

MikeDacre avatar MikeDacre commented on May 26, 2024

Closing as done in 0.6.2

from fyrd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.