473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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 1363
"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
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
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
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
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
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
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
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
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
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
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.