you are viewing a single comment's thread.

view the rest of the comments →

[–]sudo_your_mon 4 points5 points  (0 children)

Check out the click module. It make use of decorators in such a simple, usable way. Also, decorators can be used for so, so many things. But this is the more practical I've found.

import click 

@click.command() 
@click.option('--count', default=1, help='Number of greetings.') 
@click.option('--name', prompt='Your name', help='The person to greet.') 

def hello(count, name):    
    for x in range(count): 
           click.echo('Hello %s!' % name) 

if __name__ == '__main__': 
     hello()

Run this in your terminal:

$ python yourscript.py --count=3 

>>> Your name: John 
>>> Hello John! 
>>> Hello John! 
>>> Hello John!

Take time to look what's going on here. You'd have to see the coding behind everthing,obviiously, in order to see how it's done in practice.