- Original Message -
> Jean-Michel Pichavant writes:
>
> > - Original Message -
> >> Jean-Michel Pichavant wrote:
> > [snip]
> >> One minor note, the style of decorator you are using loses the
> >> docstring
> >> (at least) of the original function. I would add the
> >> @functoo
Terry Reedy於 2012年9月15日星期六UTC+8上午4時40分32秒寫道:
> 2nd try, hit send button by mistake before
>
>
>
> On 9/14/2012 5:28 AM, Jean-Michel Pichavant wrote:
>
>
>
> > Decorators are very popular so I kinda already know that the fault is
>
> > mine. Now to the reason why I have troubles writing them,
Jean-Michel Pichavant writes:
> - Original Message -
>> Jean-Michel Pichavant wrote:
> [snip]
>> One minor note, the style of decorator you are using loses the
>> docstring
>> (at least) of the original function. I would add the
>> @functools.wraps(func)
>> decorator inside your decorator
Chris Angelico於 2012年9月18日星期二UTC+8下午9時25分04秒寫道:
> On Tue, Sep 18, 2012 at 11:19 PM, Neil Cerutti wrote:
>
> > On 2012-09-14, Chris Angelico wrote:
>
> >> But then again, who actually ever needs fibonacci numbers?
>
> >
>
> > If it should happen that your question is not facetious:
>
> >
>
>
On Tue, Sep 18, 2012 at 11:19 PM, Neil Cerutti wrote:
> On 2012-09-14, Chris Angelico wrote:
>> But then again, who actually ever needs fibonacci numbers?
>
> If it should happen that your question is not facetious:
>
> http://en.wikipedia.org/wiki/Fibonacci_number#Applications
It wasn't entirel
On 2012-09-14, Chris Angelico wrote:
> But then again, who actually ever needs fibonacci numbers?
If it should happen that your question is not facetious:
http://en.wikipedia.org/wiki/Fibonacci_number#Applications
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
Am 15.09.2012 16:18 schrieb 8 Dihedral:
The concept of decorators is just a mapping from a function
... or class ...
> to another function
... or any other object ...
> with the same name in python.
Thomas
--
http://mail.python.org/mailman/listinfo/python-list
- Original Message -
> Jean-Michel Pichavant wrote:
[snip]
> One minor note, the style of decorator you are using loses the
> docstring
> (at least) of the original function. I would add the
> @functools.wraps(func)
> decorator inside your decorator.
Is there a way to not loose the funct
On Sep 15, 6:30 am, Terry Reedy wrote:
> > On 13Sep2012 18:58, alex23 wrote:
> > | On Sep 14, 3:54 am, Jean-Michel Pichavant
> > | wrote:
> > | > I don't like decorators, I think they're not worth the mental effort.
> > |
> > | Because passing a function to a function is a huge cognitive burden?
David Hutto於 2012年9月15日星期六UTC+8下午6時04分28秒寫道:
> On Sat, Sep 15, 2012 at 5:45 AM, 8 Dihedral
>
> wrote:
>
> > Steven D'Aprano於 2012年9月15日星期六UTC+8上午7時39分28秒寫道:
>
> >> On Fri, 14 Sep 2012 15:16:47 -0600, Ian Kelly wrote:
>
> >>
>
> >>
>
> >>
>
> >> > If only there were a conceptually simple
On Sat, Sep 15, 2012 at 5:45 AM, 8 Dihedral
wrote:
> Steven D'Aprano於 2012年9月15日星期六UTC+8上午7時39分28秒寫道:
>> On Fri, 14 Sep 2012 15:16:47 -0600, Ian Kelly wrote:
>>
>>
>>
>> > If only there were a conceptually simpler way to do this. Actually,
>>
>> > there is. I give you: muman than humanetadec
Steven D'Aprano於 2012年9月15日星期六UTC+8上午7時39分28秒寫道:
> On Fri, 14 Sep 2012 15:16:47 -0600, Ian Kelly wrote:
>
>
>
> > If only there were a conceptually simpler way to do this. Actually,
>
> > there is. I give you: metadecorators!
>
> [code snipped but shown below]
>
> > Which I think is certain
[Sorry, my Firefox destroyed the indent...
Am 14.09.2012 22:29 schrieb Terry Reedy:
In other words
def make_wrapper(func, param):
def wrapper(*args, **kwds):
for i in range(param):
func(*args, **kwds)
return wrapper
def f(x): print(x)
f = make_wrapper(f, 2)
f('simple')
# is simpler, at least
Dwight Hutto wrote at 2012-9-14 23:42 -0400:
> ...
>Reduce redundancy, is argumentative.
>
>To me, a decorator, is no more than a logging function. Correct me if
>I'm wrong.
Well, it depends on how you are using decorators and how complex
your decorators are. If what you are using as decorating fu
On Fri, Sep 14, 2012 at 2:40 AM, Dieter Maurer wrote:
>> On Sep 14, 3:54 am, Jean-Michel Pichavant
>> wrote:
>>> I don't like decorators, I think they're not worth the mental effort.
>
> Fine.
>
> I like them because they can vastly improve reusability and drastically
> reduce redundancies (which
On Sep 14, 6:05 am, Tim Chase wrote:
> On 09/14/12 07:01, Steven D'Aprano wrote:> [snip timeout class]
>
> > Holy over-engineering Batman!!!
>
> > No wonder you don't think much of decorators,
>
> [snip]
>
> > Most of my decorator functions are under a dozen lines. And that's the
> > complicated o
On Fri, 14 Sep 2012 15:16:47 -0600, Ian Kelly wrote:
> If only there were a conceptually simpler way to do this. Actually,
> there is. I give you: metadecorators!
[code snipped but shown below]
> Which I think is certainly easier to understand than the nested
> functions approach.
Maybe for you
Jean-Michel Pichavant wrote:
[snip]
> Ultimately, the goal is to have something like
>
> @timeout(2)
> def doAction1
>
> @timeout(4)
> def doAction2
[snip]
> Here's Steven example:
>
> # Untested!
> def timeout(t=15):
> # Decorator factory. Return a decorator to actually do the work.
>
On 14 September 2012 18:30, Chris Angelico wrote:
> On Sat, Sep 15, 2012 at 2:15 AM, andrea crotti
> wrote:
> > The poor algorithm is much more close to the mathematical definition
> > than the smarter iterative one.. And in your second version you
> > include some ugly caching logic inside it,
On Fri, Sep 14, 2012 at 2:29 PM, Terry Reedy wrote:
> For a simple, unparameterized wrapper, the difficulty is entirely in the
> wrapper maker. It must define the final wrapper as a nested function and
> return it*. It is irrelevant whether the wrapper maker is used with pre-def
> decorator syntax
On 9/14/2012 4:29 PM, Terry Reedy wrote:
On 9/13/2012 10:12 PM, Cameron Simpson wrote:
On 13Sep2012 18:58, alex23 wrote:
| On Sep 14, 3:54 am, Jean-Michel Pichavant
| wrote:
| > I don't like decorators, I think they're not worth the mental effort.
|
| Because passing a function to a function i
2nd try, hit send button by mistake before
On 9/14/2012 5:28 AM, Jean-Michel Pichavant wrote:
Decorators are very popular so I kinda already know that the fault is
mine. Now to the reason why I have troubles writing them, I don't
know. Every time I did use decorators, I spent way too much time
On 9/14/2012 5:28 AM, Jean-Michel Pichavant wrote:
Decorators are very popular so I kinda already know that the fault is mine. Now
to the reason why I have troubles writing them, I don't know. Every time I did
use decorators, I spent way too much time writing it (and debugging it).
--
Terry
On 9/13/2012 10:12 PM, Cameron Simpson wrote:
On 13Sep2012 18:58, alex23 wrote:
| On Sep 14, 3:54 am, Jean-Michel Pichavant
| wrote:
| > I don't like decorators, I think they're not worth the mental effort.
|
| Because passing a function to a function is a huge cognitive burden?
For parameter
On Sat, Sep 15, 2012 at 2:15 AM, andrea crotti
wrote:
> The poor algorithm is much more close to the mathematical definition
> than the smarter iterative one.. And in your second version you
> include some ugly caching logic inside it, so why not using a
> decorator then?
I learned Fibonacci as
Chris Angelico於 2012年9月14日星期五UTC+8下午10時41分06秒寫道:
> On Sat, Sep 15, 2012 at 12:12 AM, andrea crotti
>
> wrote:
>
> > def fib(n):
>
> > if n <= 1:
>
> > return 1
>
> > return fib(n-1) + fib(n-2)
>
> >
>
> > @memoize
>
> > def fib_memoized(n):
>
> > if n <= 1:
>
> >
2012/9/14 Chris Angelico :
>
> Trouble is, you're starting with a pretty poor algorithm. It's easy to
> improve on what's poor. Memoization can still help, but I would start
> with a better algorithm, such as:
>
> def fib(n):
> if n<=1: return 1
> a,b=1,1
> for i in range(1,
- Original Message -
> On Fri, 14 Sep 2012 15:22:26 +0200, Jean-Michel Pichavant wrote:
>
> > Here's Steven example:
> >
> > # Untested!
> > def timeout(t=15):
> > # Decorator factory. Return a decorator to actually do the
> > work. if
> > FPGA:
> > t *= 3
> > def
On Fri, 14 Sep 2012 15:22:26 +0200, Jean-Michel Pichavant wrote:
> Here's Steven example:
>
> # Untested!
> def timeout(t=15):
> # Decorator factory. Return a decorator to actually do the work. if
> FPGA:
> t *= 3
> def decorator(func):
> @functools.wraps(func)
>
On Sat, Sep 15, 2012 at 12:12 AM, andrea crotti
wrote:
> def fib(n):
> if n <= 1:
> return 1
> return fib(n-1) + fib(n-2)
>
> @memoize
> def fib_memoized(n):
> if n <= 1:
> return 1
> return fib_memoized(n-1) + fib_memoized(n-2)
>
>
> The second fibonacci looks exac
I think one very nice and simple example of how decorators can be used is this:
def memoize(f, cache={}, *args, **kwargs):
def _memoize(*args, **kwargs):
key = (args, str(kwargs))
if not key in cache:
cache[key] = f(*args, **kwargs)
return cache[key]
r
- Original Message -
> Jean-Michel Pichavant wrote:
>
> > I wrote the following one, used to decorate any function that
> > access
> > an equipment, it raises an exception when the timeout expires. The
> > timeout is adapted to the platform, ASIC of FPGA so people don't
> > need
> > to
On 09/14/12 07:01, Steven D'Aprano wrote:
> [snip timeout class]
>
> Holy over-engineering Batman!!!
>
> No wonder you don't think much of decorators,
[snip]
> Most of my decorator functions are under a dozen lines. And that's the
> complicated ones!
As are mine, and a sizable chunk of those
Am 14.09.2012 11:28, schrieb Jean-Michel Pichavant:
Decorators are very popular so I kinda already know that the
fault is mine. Now to the reason why I have troubles writing
them, I don't know. Every time I did use decorators, I spent
way too much time writing it (and debugging it).
I wrote the
On Fri, 14 Sep 2012 11:28:22 +0200, Jean-Michel Pichavant wrote:
> PS : Here's the decorator, just to give you an idea about how it looks.
> Small piece of code, but took me more than 2 hours to write it. I
> removed some sensible parts so I don't expect it to run.
[snip timeout class]
Holy over
Jean-Michel Pichavant wrote:
> I wrote the following one, used to decorate any function that access
> an equipment, it raises an exception when the timeout expires. The
> timeout is adapted to the platform, ASIC of FPGA so people don't need
> to specify everytime one timeout per platform.
>
> I
- Original Message -
> On Sep 14, 3:54 am, Jean-Michel Pichavant
> wrote:
> > I don't like decorators, I think they're not worth the mental
> > effort.
>
> Because passing a function to a function is a huge cognitive burden?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
I
> On Sep 14, 3:54 am, Jean-Michel Pichavant
> wrote:
>> I don't like decorators, I think they're not worth the mental effort.
Fine.
I like them because they can vastly improve reusability and drastically
reduce redundancies (which I hate). Improved reusability and
reduced redundancies can make a
On Sep 14, 12:12 pm, Cameron Simpson wrote:
> On 13Sep2012 18:58, alex23 wrote:
> | On Sep 14, 3:54 am, Jean-Michel Pichavant | wrote:
> | > I don't like decorators, I think they're not worth the mental effort.
> |
> | Because passing a function to a function is a huge cognitive burden?
>
> It is
On 13Sep2012 18:58, alex23 wrote:
| On Sep 14, 3:54 am, Jean-Michel Pichavant
| wrote:
| > I don't like decorators, I think they're not worth the mental effort.
|
| Because passing a function to a function is a huge cognitive burden?
It is for me when I'm _writing_ the decorator:-) But if I get
40 matches
Mail list logo