I love the decorator in Python!!!

Andrew Berg bahamutzero8825 at gmail.com
Thu Dec 8 11:55:29 EST 2011


Decorators are great for adding common functionality to several
functions without duplicating code. For example, I have one for my IRC
bot that checks that the person sending the command is authorized to use
the command. It's only "if mask in owner list then execute function else
say access denied", but it simplifies the code and the intent of each
function that uses it becomes more obvious. I have another that puts
functions in a common try/except clause, which again simplifies the
functions and makes them easier to understand.

-- 
CPython 3.2.2 | Windows NT 6.1.7601.17640 | Thunderbird 7.0



More information about the Python-list mailing list