473,507 Members | 13,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

decorators

I must be very thick. I keep reading about what decorators are and I
still don't have a good feel about it. See, for example:

http://alex.dojotoolkit.org/?p=564

and:

http://soiland.no/software/decorator

What exactly do I use decorators for?

Nov 8 '06 #1
4 1367
"John Henry" <jo**********@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>I must be very thick. I keep reading about what decorators are and I
still don't have a good feel about it. See, for example:

http://alex.dojotoolkit.org/?p=564

and:

http://soiland.no/software/decorator

What exactly do I use decorators for?
John -

See if any of these examples give you some ideas on how you might use a
decorator: http://wiki.python.org/moin/PythonDecoratorLibrary

-- Paul
Nov 8 '06 #2
On Wed, 2006-11-08 at 12:37 -0800, John Henry wrote:
I must be very thick. I keep reading about what decorators are and I
still don't have a good feel about it. See, for example:

http://alex.dojotoolkit.org/?p=564

and:

http://soiland.no/software/decorator

What exactly do I use decorators for?
Decorators are a tool for executing common code when a function is
defined and/or when it's called. This reduces code duplication by
allowing you to factor out commonly performed steps.

If you find yourself writing different functions that share a lot of
setup/teardown code, or if you find yourself doing a lot of repetitive
housekeeping for each function you're defining, decorators eliminate
this duplication.

You've already been given a bunch of different examples, so I won't bore
you with more contrived examples. If none of the examples make you say
"wow, I could use this" and if you don't find yourself writing
repetitive setup/teardown/housekeeping code, you can probably live quite
comfortably without using decorators.

-Carsten
Nov 8 '06 #3

John Henry wrote:
I must be very thick. I keep reading about what decorators are and I
still don't have a good feel about it. See, for example:

http://alex.dojotoolkit.org/?p=564

and:

http://soiland.no/software/decorator

What exactly do I use decorators for?
Here's my learning experience on decorators:
http://paddy3118.blogspot.com/2006/0...ttributes.html
especially:
http://paddy3118.blogspot.com/2006/0...signed-by.html

Nov 8 '06 #4
"Carsten Haese" <ca*****@uniqsys.comwrote in message
news:ma***************************************@pyt hon.org...
If none of the examples make you say
"wow, I could use this" and if you don't find yourself writing
repetitive setup/teardown/housekeeping code, you can probably live quite
comfortably without using decorators.
Amen! Don't force yourself to learn decorators if you don't need them at
the moment. Wait until you start repeating the same code (lock/unlock,
dbready/dbcommit, logstart/logend, etc.) around multiple functions, then go
back and try applying a decorator to simplify the job. Having a real use
for them will make it much easier to "get".

I will say, though, that I found the memoizing decorator to be especially
intriguing and eye-opening, and didn't realize I needed it until I saw it
laid out in front of me.

-- Paul
Nov 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2049
by: Michael Sparks | last post by:
Anyway... At Europython Guido discussed with everyone the outstanding issue with decorators and there was a clear majority in favour of having them, which was good. From where I was sitting it...
17
1746
by: daishi | last post by:
For what it's worth: As far as I know, the proposed @decorator syntax will be the first time that two logical lines of python with the same indentation will not be independent of one another....
8
1595
by: Michele Simionato | last post by:
Decorators can generate endless debate about syntax, but can also be put to better use ;) Actually I was waiting for decorators to play a few tricks that were syntactically too ugly to be even...
4
1472
by: RebelGeekz | last post by:
Just my humble opinion: def bar(low,high): meta: accepts(int,int) returns(float) #more code Use a metadata section, no need to introduce new messy symbols, or mangling our beloved visual...
11
1533
by: Arien Malec | last post by:
I've been following the decorator debate with some interest, and it's taken me a reasonably long time to understand what is meant by a decorator. One of the issues is that the Decorator pattern is...
2
1695
by: Guido van Rossum | last post by:
Robert and Python-dev, I've read the J2 proposal up and down several times, pondered all the issues, and slept on it for a night, and I still don't like it enough to accept it. The only reason...
0
2329
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
13
2337
by: km | last post by:
Hi all, was going thru the new features introduced into python2.4 version. i was stuck with 'decorators' - can someone explain me the need of such a thing called decorators ? tia KM
11
2079
by: Helmut Jarausch | last post by:
Hi, are decorators more than just syntactic sugar in python 2.x and what about python 3k ? How can I find out the predefined decorators? Many thanks for your help, Helmut Jarausch
2
1941
by: Andrew West | last post by:
Probably a bit of weird question. I realise decorators shouldn't be executed until the function they are defined with are called, but is there anyway for me to find all the decorates declared in a...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.