On Mon, 14 Nov 2011 17:00:38 -0800, Russell E. Owen wrote:
> Oops, I stripped so much out of my example that I stripped the ugly bit.
> This is closer to the original and demonstrated the issue:
>
> def timeMethod(func):
> name = func.__name__ + "Duration"
> def wrapper(self, *args, **key
In article
,
Ian Kelly wrote:
> On Thu, Nov 10, 2011 at 2:52 PM, Russell E. Owen wrote:
> > I am trying to write a decorator that times an instance method and
> > writes the results to a class member variable. For example:
> >
> > def timeMethod(func):
> > def wrapper(self, *args, **keyArgs
On Thu, Nov 10, 2011 at 2:52 PM, Russell E. Owen wrote:
> I am trying to write a decorator that times an instance method and
> writes the results to a class member variable. For example:
>
> def timeMethod(func):
> def wrapper(self, *args, **keyArgs):
> t1 = time.time()
> res = fu
I am trying to write a decorator that times an instance method and
writes the results to a class member variable. For example:
def timeMethod(func):
def wrapper(self, *args, **keyArgs):
t1 = time.time()
res = func(self, *args, **keyArgs)
duration = time.time() - t1
On Jan 27, 2:42 am, "Thomas L. Shinnick" wrote:
> At 08:17 PM 1/26/2011, Chris wrote:
>
> >I have a class (A, for instance) that possesses a boolean (A.b, for
> >instance) that is liable to change over an instance's lifetime.
>
> >Many of the methods of this class (A.foo, for instance) should not
At 08:17 PM 1/26/2011, Chris wrote:
I have a class (A, for instance) that possesses a boolean (A.b, for
instance) that is liable to change over an instance's lifetime.
Many of the methods of this class (A.foo, for instance) should not
execute as long as this boolean is false, but should instead
On 27/01/2011 02:17, Chris wrote:
I have a class (A, for instance) that possesses a boolean (A.b, for
instance) that is liable to change over an instance's lifetime.
Many of the methods of this class (A.foo, for instance) should not
execute as long as this boolean is false, but should instead ra
On Jan 26, 6:17 pm, Chris wrote:
> I have a class (A, for instance) that possesses a boolean (A.b, for
> instance) that is liable to change over an instance's lifetime.
>
> Many of the methods of this class (A.foo, for instance) should not
> execute as long as this boolean is false, but should ins
I have a class (A, for instance) that possesses a boolean (A.b, for
instance) that is liable to change over an instance's lifetime.
Many of the methods of this class (A.foo, for instance) should not
execute as long as this boolean is false, but should instead raise an
exception.
Can I use a decor
On 16 Okt, 16:49, Peter Otten <__pete...@web.de> wrote:
> Lucasm wrote:
> > I have a decorator problem and hope someone is able to help me out/
> > assist me. Thanks in advance.
>
> > Suppose:
> > ### Begin some_library_module ###
>
> > def some_decorator(some_method):
> > def inner(an_arg, *ar
Lucasm wrote:
> I have a decorator problem and hope someone is able to help me out/
> assist me. Thanks in advance.
>
> Suppose:
> ### Begin some_library_module ###
>
> def some_decorator(some_method):
> def inner(an_arg, *args, **kwargs):
> return some_method(an_arg, *args, **kwargs
Hello,
I have a decorator problem and hope someone is able to help me out/
assist me. Thanks in advance.
Suppose:
### Begin some_library_module ###
def some_decorator(some_method):
def inner(an_arg, *args, **kwargs):
return some_method(an_arg, *args, **kwargs)
return inner
### E
Bruno Desthuilliers wrote:
Short answer: this makes no sense.
Absolutely right, took me a while to figure that out though :-)
Lesson learned (again): If it really seems impossible to do something in
Python, it is likely the proposed solution is flawed.
--
MPH
http://blog.dcuktec.com
'If con
Martin P. Hellwig a écrit :
Hi all,
I have been trying out to wrap my mind around the advantages of
decorators and thought I found a use in one of my experiments. (see code
after my sig).
Although it works, I think it should be able to do it better.
My particular problem is that I want to re
Hi all,
I have been trying out to wrap my mind around the advantages of
decorators and thought I found a use in one of my experiments. (see code
after my sig).
Although it works, I think it should be able to do it better.
My particular problem is that I want to remove an argument (say always
If you are using Python 2.5, you can use functools.update_wrapper to
simplify your life. For instance
from functools import update_wrapper # requires Python 2.5
def trace(func):
def wrapper(*args,**kw):
print 'calling %s with args %s' % (func.__name__,args)
return func(*args,*
On 23 May, 14:46, "Steven W. Orr" <[EMAIL PROTECTED]> wrote:
> I just discovered decorators. Very cool. My question is that I can't
> figure out how to make a decorator not be restricted to a function so it
> would also work on a method.
>
> Here's my code:
>
> def g(expr):
> def rpt(func):
>
Steven W. Orr wrote:
> I just discovered decorators. Very cool. My question is that I can't
> figure out how to make a decorator not be restricted to a function so it
> would also work on a method.
>
> Here's my code:
> @g(20)
> def f(s):
> print 's="%s"'%s
> f('Hello')
Here you are callin
I just discovered decorators. Very cool. My question is that I can't
figure out how to make a decorator not be restricted to a function so it
would also work on a method.
Here's my code:
def g(expr):
def rpt(func):
def wrapper(t):
for ii in range(expr):
Schüle Daniel wrote:
> Can someone give me some pointers to the metaprogramming in Python?
> links etc
Check the Python Wiki. For the decorators in particular I wrote a
module that
you may find useful. See
http://www.phyast.pitt.edu/~micheles/python/decorator.zip
http://www.phyast.pitt.edu/~miche
Bengt Richter wrote:
>>is it possible to pass parameters to a decorator function?
>>
> Yes, but then the function must return the same kind of thing
> a bare decorator-function name would have, which is a function
> able to take a single argument of a function and return a function.
>
> So your de
thx to all
now I understand how it works and why it should be done in this way
so it's possible to write more than only one declarator
>>> def foo(f):
... l = [1]
... def method(*a,**kw):
... f(l, *a, **kw)
... return method
...
>>> def bar(f):
... l = [2]
... de
On Sun, 08 Jan 2006 23:26:28 +0100, =?ISO-8859-1?Q?Sch=FCle_Daniel?= <[EMAIL
PROTECTED]> wrote:
[...]
>
>the code above works fine
>but I am wondering wheather it's possible to
>write something like this
>
> >>> def timelogger(f, logfile=sys.stdout):
>... def wrapper(*a,**kw):
>...
Schüle Daniel schrieb:
> hello NG,
>
> consider this code
>
> >>> def timelogger(f):
> ... def wrapper(*a,**kw):
> ... print "started at %s" % time.ctime()
> ... t0 = time.time()
> ... f(*a, **kw)
> ... t1 = time.time()
> ... print
Schüle Daniel wrote:
>
> (1) fails to compile
> is it possible to pass parameters to a decorator function?
Yes, I think this does what you want:
import time, sys
def timelogger(logfile=sys.stdout):
def actual_timelogger(function):
def wrapper(*a,**kw):
logfile.write("
hello NG,
consider this code
>>> def timelogger(f):
... def wrapper(*a,**kw):
... print "started at %s" % time.ctime()
... t0 = time.time()
... f(*a, **kw)
... t1 = time.time()
... print "ended at %s" % time.ctime()
...
26 matches
Mail list logo