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
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
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
> 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
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
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
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
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
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
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
*.. 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
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
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
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.
>>
>>
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
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
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(
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
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
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
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
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
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
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
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
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
"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
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
: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
> >
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?
> >
> >
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
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):
> >
> >
>>> > 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
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
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?
>
>
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
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
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
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
>> 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
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
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
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
>> 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
> 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
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
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
>> 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
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
> 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
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
> 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
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
53 matches
Mail list logo