Re: [Tutor] decorators in a class

2017-06-13 Thread Peter Otten
anish singh wrote: > Trying to use decorators in my class. I am calling > build_tree from the main function and i want to increment > the arguments by a constant factor by using decorators. > However as build_tree is a recursive function, I don't want > to call it recursively with increased consta

Re: [Tutor] decorators -- treat me like i'm 6.. what are they.. why are they?

2016-07-07 Thread Alan Gauld via Tutor
On 06/07/16 20:35, bruce wrote: > But, what are decorators, why are decorators? who decided you needed them! Thinking about this a little wider than Python. Decorators are a standard software design pattern and were first(?) formally documented in the famous book known as the "Gang of Four" (GoF

Re: [Tutor] decorators -- treat me like i'm 6.. what are they.. why are they?

2016-07-06 Thread Steven D'Aprano
On Wed, Jul 06, 2016 at 03:35:16PM -0400, bruce wrote: > Hi. > > Saw the decorator thread earlier.. didn't want to pollute it. I know, > I could google! > > But, what are decorators, why are decorators? who decided you needed > them! Sometimes you find yourself writing many functions (or metho

Re: [Tutor] decorators -- treat me like i'm 6.. what are they.. why are they?

2016-07-06 Thread Danny Yoo
> As to who suggested them you'd need to go back through the > PEPs to see who first suggested it, and then maybe more to see > who's idea finally got accepted. I think it was in Python 2.5. Hi Bruce, Yes, it happened back around 2003: https://www.python.org/dev/peps/pep-0318/ Decorators

Re: [Tutor] decorators -- treat me like i'm 6.. what are they.. why are they?

2016-07-06 Thread Alan Gauld via Tutor
On 06/07/16 20:35, bruce wrote: > Saw the decorator thread earlier.. didn't want to pollute it. I know, I > could google! > > But, what are decorators, why are decorators? who decided you needed them! decorators are things that modify functions in standard ways. Specifically they are functions t

Re: [Tutor] decorators -- treat me like i'm 6.. what are they.. why are they?

2016-07-06 Thread Alex Hall
On Wed, Jul 6, 2016 at 4:56 PM, Alex Hall wrote: > > > On Wed, Jul 6, 2016 at 3:35 PM, bruce wrote: > >> Hi. >> >> Saw the decorator thread earlier.. didn't want to pollute it. I know, I >> could google! >> >> But, what are decorators, why are decorators? who decided you needed them! >> > > I th

Re: [Tutor] decorators -- treat me like i'm 6.. what are they.. why are they?

2016-07-06 Thread Alex Hall
On Wed, Jul 6, 2016 at 3:35 PM, bruce wrote: > Hi. > > Saw the decorator thread earlier.. didn't want to pollute it. I know, I > could google! > > But, what are decorators, why are decorators? who decided you needed them! > They're functions that modify the decorated function. If I make a functi

Re: [Tutor] Decorators: Are they good for checking inputs and outputs?

2013-01-07 Thread Steven D'Aprano
On 06/01/13 23:30, DoanVietTrungAtGmail wrote: Dear tutors After much reading and head-scratching, I think the basic idea of decorators has now clicked for me. I am a beginner in programming and in Python, but I want to eventually develop a serious system. To spend most of my time on developing

Re: [Tutor] Decorators: Are they good for checking inputs and outputs?

2013-01-06 Thread Dave Angel
On 01/06/2013 07:13 PM, DoanVietTrungAtGmail wrote: > *.. Could you perhaps give a concrete example of a situation where > a decorator would be useful for checking the inputs to a function? .. Oscar* > > Say I write a function that expects 5 positional arguments, and up to 4 ** > arguments. Now I w

Re: [Tutor] Decorators: Are they good for checking inputs and outputs?

2013-01-06 Thread Oscar Benjamin
On 7 January 2013 00:13, DoanVietTrungAtGmail wrote: > .. Could you perhaps give a concrete example of a situation where a > decorator would be useful for checking the inputs to a function? .. Oscar > > Say I write a function that expects 5 positional arguments, and up to 4 ** > arguments. Now I w

Re: [Tutor] Decorators: Are they good for checking inputs and outputs?

2013-01-06 Thread DoanVietTrungAtGmail
*.. Could you perhaps give a concrete example of a situation where a decorator would be useful for checking the inputs to a function? .. Oscar* Say I write a function that expects 5 positional arguments, and up to 4 ** arguments. Now I want to: a- check that the first positional argument is a sort

Re: [Tutor] Decorators: Are they good for checking inputs and outputs?

2013-01-06 Thread Oscar Benjamin
On 6 January 2013 12:30, DoanVietTrungAtGmail wrote: > Dear tutors > > After much reading and head-scratching, I think the basic idea of decorators > has now clicked for me. I am a beginner in programming and in Python, but I > want to eventually develop a serious system. To spend most of my time

Re: [Tutor] Decorators: Are they good for checking inputs and outputs?

2013-01-06 Thread Alan Gauld
On 06/01/13 12:30, DoanVietTrungAtGmail wrote: After much reading and head-scratching, I think the basic idea of decorators has now clicked for me. Congratulations. It's always good when a new concept finally slots in place. One thing - do you understand the downsides of decorators too? Every

Re: [Tutor] decorators

2011-06-30 Thread Christopher King
It would be cool if their where decorators that modified decorators. I know its possible, but I can't think of a use. On Thu, Jun 23, 2011 at 11:05 PM, Steven D'Aprano wrote: > Robert wrote: > >> Is there a good tutorial out there somewhere about decorators? Google >> doesn't bring up much. >> >>

Re: [Tutor] decorators

2011-06-24 Thread Steven D'Aprano
Prasad, Ramit wrote: Excellent explanation Steven; I understood the mechanical basics but this has made the reason behind it a lot clearer. If test_argument is only being passed the function how does it have access to the arguments? It doesn't. There are three functions involved. The first is

Re: [Tutor] decorators

2011-06-24 Thread python
Steven, > Here's my cheap introduction to decorators... Beautifully explained! Thank you, Malcolm (not the OP) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] decorators

2011-06-24 Thread Prasad, Ramit
Excellent explanation Steven; I understood the mechanical basics but this has made the reason behind it a lot clearer. If test_argument is only being passed the function how does it have access to the arguments? Or is that more syntactic sugar / abbreviation for explanation? def test_argument(

Re: [Tutor] decorators

2011-06-23 Thread Steven D'Aprano
Robert wrote: Is there a good tutorial out there somewhere about decorators? Google doesn't bring up much. Define "good" :) I'm interested in what you think about this article: http://www.artima.com/weblogs/viewpost.jsp?thread=240808 Personally, I think it's filled with jargon that will b

Re: [Tutor] decorators (the "at" sign)?

2010-10-31 Thread Siren Saren
pecially if your working with anything visual that you'd like to display. Cheers, Soren --- On Tue, 10/26/10, Lie Ryan wrote: From: Lie Ryan Subject: Re: [Tutor] decorators (the "at" sign)? To: tutor@python.org Date: Tuesday, October 26, 2010, 12:30 PM On 10/26/10 13:46, Al

Re: [Tutor] decorators (the "at" sign)?

2010-10-27 Thread Alex Hall
Thanks to all for the explanations. I think I understand how this works, basically. I doubt I will use the concept anytime soon, but I think I get it enough to follow what is happening in the source code of the application I am examining. On 10/27/10, Siren Saren wrote: > Alex, > > Many people ha

Re: [Tutor] decorators (the "at" sign)?

2010-10-27 Thread Siren Saren
Alex, Many people have trouble wrapping their minds around decorators.  I couldn't find a decent explanation either until reading an allegedly 'advanced' python book (b/c 'advanced' is in the title, I guess). An easy explanation might be sufficient, if you don't intend to use them yourself.  A

Re: [Tutor] decorators (the "at" sign)?

2010-10-26 Thread Lie Ryan
On 10/26/10 13:46, Alex Hall wrote: > Hi all, > Now that I am able to run the source code of an open source > application I hope to one day help develop, I am trying to understand > how it works. One thing I keep seeing is an at sign followed by a > word, usually (maybe always) immediately preceedi

Re: [Tutor] decorators (the "at" sign)?

2010-10-25 Thread James Mills
On Tue, Oct 26, 2010 at 12:46 PM, Alex Hall wrote: > �...@set_index >  def get_url(self, index=None): >  return self.storage[index]['Url'] Decorators in python are used (almost as convenience) to wrap functions/methods for various purposes. It might be to do some logging before and after the actu

Re: [Tutor] decorators

2010-07-23 Thread Peter Otten
Mary Morris wrote: > I'm trying to compile a list of decorators from the source code at my > office. > I did this by doing a > > candidate_line.find("@") > > because all of our decorators start with the @ symbol. The problem I'm > having is that the email addresses that are included in the comm

Re: [Tutor] decorators

2010-07-23 Thread Steven D'Aprano
On Sat, 24 Jul 2010 04:23:41 am Mary Morris wrote: > I'm trying to compile a list of decorators from the source code at my > office. > I did this by doing a > > candidate_line.find("@") > > because all of our decorators start with the @ symbol. The problem > I'm having is that the email addresses

Re: [Tutor] decorators

2010-07-23 Thread शंतनू
On Friday 23 July 2010 11:53 PM, Mary Morris wrote: I'm trying to compile a list of decorators from the source code at my office. I did this by doing a candidate_line.find("@") How about using something like candidate_line.strip.startswith('@') and calculate_line.find('.') == -1 There are f

Re: [Tutor] Decorators

2010-06-30 Thread Alan Gauld
"Mary Morris" wrote anything. I need to find out every decorator and make sure it has a descriptive name. I was thinking I could write a simple script which would parse through all of the source files and find decorators-maybe by looking for the @ symbol? I would first try a good IDE. I

Re: [Tutor] Decorators

2010-06-30 Thread Hugo Arts
On Wed, Jun 30, 2010 at 9:52 PM, Mary Morris wrote: > I need help with the following task for my new job: > The code we're using is python, which I have never worked with before. > Our AMS source code relies heavily on decorators.Things look something like > this: > @decomaker(argA, argB, ...) > d

Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread Vince Spicer
:05 -0700 > > Von: wesley chun > > An: vince spicer , tmatsum...@gmx.net > > CC: Kent Johnson , tutor@python.org > > Betreff: Re: [Tutor] decorators, __call__ (able) objects > > > > >>> > Can some one give, or point to some good examples of how > >

Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread Todd Matsumoto
ce spicer , tmatsum...@gmx.net > CC: Kent Johnson , tutor@python.org > Betreff: Re: [Tutor] decorators, __call__ (able) objects > >>> > Can some one give, or point to some good examples of how @decorators > >>> > work, and __call__ (able) objects? > > > >

Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread Todd Matsumoto
hi kent, thanks, i read through the link but still haven't got my head around this concept. will read on. cheers, t Original-Nachricht > Datum: Wed, 15 Jul 2009 08:33:33 -0400 > Von: Kent Johnson > An: Todd Matsumoto > CC: tutor@python.org > Betreff: Re

Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread vince spicer
agreed much better description, thanks On Wed, Jul 15, 2009 at 1:02 PM, wesley chun wrote: > >>> > Can some one give, or point to some good examples of how @decorators > >>> > work, and __call__ (able) objects? > > > > simple example of calling a class > > > > class myKlass(object): > > > >

Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread wesley chun
>>> > Can some one give, or point to some good examples of how @decorators >>> > work, and __call__ (able) objects? > > simple example of calling a class > > class myKlass(object): > > def __call__(self, *args, **kws): > print "i was called" > > >>> test = myKlass() > >>> test() > i wa

Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread vince spicer
simple example of calling a class class myKlass(object): def __call__(self, *args, **kws): print "i was called" >> test = myKlass() >> test() >> i was called > > > > On Wed, Jul 15, 2009 at 6:33 AM, Kent Johnson wrote: > >> On Wed, Jul 15, 2009 at 7:41 AM, Todd Matsumoto >> wr

Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread vince spicer
simple example of calling a class class myKlass(object): On Wed, Jul 15, 2009 at 6:33 AM, Kent Johnson wrote: > On Wed, Jul 15, 2009 at 7:41 AM, Todd Matsumoto wrote: > > Hi, > > > > Can some one give, or point to some good examples of how @decorators > work, and __call__ (able) objects? > >

Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread Kent Johnson
On Wed, Jul 15, 2009 at 7:41 AM, Todd Matsumoto wrote: > Hi, > > Can some one give, or point to some good examples of how @decorators work, > and __call__ (able) objects? Decorators: http://personalpages.tds.net/~kent37/kk/1.html Kent ___ Tutor mai

Re: [Tutor] Decorators and function arguments.

2007-09-19 Thread Noufal Ibrahim
Kent Johnson wrote: > Noufal Ibrahim wrote: >> My question is whether this is a valid use for a decorator and whether >> this kind of usage is pythonic. If not, are there any better ways to >> do this? > > It seems like a bit of a hack to me. I guess you change the way you call > run_command to

Re: [Tutor] Decorators and function arguments.

2007-09-19 Thread Kent Johnson
Noufal Ibrahim wrote: > My question is whether this is a valid use for a decorator and whether > this kind of usage is pythonic. If not, are there any better ways to do > this? It seems like a bit of a hack to me. I guess you change the way you call run_command to include desc? You could add a

Re: [Tutor] Decorators

2006-04-11 Thread Victor Bouffier
On Tue, 2006-04-11 at 21:08 +0100, Alan Gauld wrote: > What was an easy to learn and use, ideal language > for medium sized to fairly large scripting projects is trying to turn > into > an all encompassing general purpose language which will be > increasingly difficult to use without falling down s

Re: [Tutor] Decorators

2006-04-11 Thread Alan Gauld
>> Ah, but by that standard even assembler is syntactic sugar, now >> where are those hex codes and my keypunch? :-) > Only those of us who keyed the bin loader into a PDP-8 by toggling > switches, each representing one bit, can claim to be the most free of > syntactic sugar. Never used a PDP 8

Re: [Tutor] Decorators

2006-04-11 Thread Bob Gailer
Andrew D. Fant wrote: > [snip] try crossing lisp > with APL for a mathematically pure language that nobody can ever read. > One problem is that APL allowed unbalanced parentheses (as in )SAVE), whereas LISP does not. And of course there is the right-to-left vs left-to-right issue... I do mis

Re: [Tutor] Decorators

2006-04-11 Thread Andrew D. Fant
Alan Gauld wrote: >>Syntactic sugar *IS* a practical benefit. After all, every language above >>assember is syntactic sugar, and by your definition of no practical use. > > > Ah, but by that standard even assembler is syntactic sugar, now > where are those hex codes and my keypunch? :-) > > By p

Re: [Tutor] Decorators

2006-04-11 Thread Bob Gailer
Alan Gauld wrote: >> Syntactic sugar *IS* a practical benefit. After all, every language above >> assember is syntactic sugar, and by your definition of no practical use. >> > > Ah, but by that standard even assembler is syntactic sugar, now > where are those hex codes and my keypunch? :-) Onl

Re: [Tutor] Decorators

2006-04-11 Thread Alan Gauld
>> I really don't like this proposal nor many of the others that currently >> exist to seemingly turn Python into Java and C++! If people want to > > FWIW there is enough perceived need for this (and adapters or protocols) > that it has been invented already two or three times, in PEAK (by Philip

Re: [Tutor] Decorators

2006-04-11 Thread Alan Gauld
> Syntactic sugar *IS* a practical benefit. After all, every language above > assember is syntactic sugar, and by your definition of no practical use. Ah, but by that standard even assembler is syntactic sugar, now where are those hex codes and my keypunch? :-) By practical use I mean adding func

Re: [Tutor] Decorators

2006-04-11 Thread Kent Johnson
Alan Gauld wrote: >> proposal for dynamic function overloading: >> http://www.artima.com/weblogs/viewpost.jsp?thread=155514 > > I really don't like this proposal nor many of the others that currently > exist to seemingly turn Python into Java and C++! If people want to > code in the Java porridg

Re: [Tutor] Decorators

2006-04-11 Thread Michael
On Tuesday 11 April 2006 17:43, Alan Gauld wrote: > >> There is no practical use for decorators IMHO > > > > It's true that decorators are syntactic sugar and don't add any new > > functional capabilities to the language. > > Which is all I intended to imply. You have a different meaning of "pract

Re: [Tutor] Decorators

2006-04-11 Thread Alan Gauld
>> There is no practical use for decorators IMHO > It's true that decorators are syntactic sugar and don't add any new > functional capabilities to the language. Which is all I intended to imply. > However this doesn't mean that there is no practical use for decorators. Nor did I mean that, af

Re: [Tutor] Decorators

2006-04-11 Thread Kent Johnson
Alan Gauld wrote: >> My problem, and this is after reading PEP 318 and other items found when I >> "Googled" for decorators, is that I can't figure out the practical use for > > There is no practical use for decorators IMHO > They are syntactic sugar added to the language to make some things > tha

Re: [Tutor] Decorators

2006-04-11 Thread Alan Gauld
> My problem, and this is after reading PEP 318 and other items found when I > "Googled" for decorators, is that I can't figure out the practical use for There is no practical use for decorators IMHO They are syntactic sugar added to the language to make some things that were already possible a li

Re: [Tutor] Decorators

2006-04-10 Thread Kent Johnson
Greg Lindstrom wrote: > Hello- > > For some reason I have decided to learn about decorators; I heard them > talked up at Pycon the past two years and want to know what all the > fuss is about. I might even use them in my code :-) > > My problem, and this is after reading PEP 318 and other ite

Re: [Tutor] Decorators, I am confused.

2005-07-14 Thread Alan G
> class testObj(object): >_rules = list() >def evalRules(self): >for r in _rules: >r() >def rule(func): >if not func in func.__class__._rules: >... >def arule(self): >print a Can you explain in plain English what testObj does? I don;t unders

Re: [Tutor] Decorators, I am confused.

2005-07-14 Thread Kent Johnson
David Driver wrote: > What I would like to do is something like this: > > class testObj(object): > _rules = list() > def evalRules(self): > for r in _rules: > r() > def rule(func): > if not func in func.__class__._rules: > func.__class__._rules.a