473,569 Members | 2,402 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 1371
"John Henry" <jo**********@h otmail.comwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.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*****@uniqsy s.comwrote in message
news:ma******** *************** *************** *@python.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
2051
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 looked like about 20:20 split on the following syntaxes: 1 def func(arg1, arg2, arg3) : function... 2 def func(arg1, arg2, arg3):...
17
1756
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. Previously, when looking at: some_python(code) and_some_more = stuff there was no need to look at the the first line in order to know what
8
1602
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 imaginable for Python 2.3. One trick is to use decorators to implement multimethods. A while ago Howard Stearns posted here a recipe to implement...
4
1477
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 cleanliness of python.
11
1544
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 more like a Unix pipe than it is what PEP 318 calls a decorator. The classic decorator is run-time, rather than define time, and is non-destructive...
2
1699
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 to accept it would be to pacify the supporters of the proposal, and that just isn't a good enough reason in language design. However, it got...
0
2331
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 Methods Version: $Revision: 1.34 $ Last-Modified: $Date: 2004/09/03 09:32:50 $ Author: Kevin D. Smith, Jim Jewett, Skip Montanaro, Anthony Baxter
13
2344
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
2083
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
1942
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 file when I import it? Or perhaps anyway to find the decorators by loading the file by other methods (with out simply parsing it by hand). ...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
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 we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.