Thanks folks,
Tried all of these, and went with staticmethod(). Was cleanest
solution,
> After skimming over Steven's post: use staticmethod.
> No idea why I didn't think of that myself.
Kannan
--
http://mail.python.org/mailman/listinfo/python-list
Peter Otten wrote:
> or you wrap the callable in a descriptor:
>
def DefaultTracer(*args): print args
> ...
class D(object):
> ... def __init__(self, f):
> ... self.f = f
> ... def __get__(self, *args):
> ... return self.f
> ...
After skimming over Steve
Steven D'Aprano writes:
> Please don't post code with line numbers. That makes it difficult to copy
> and paste your function into an interactive session, so that we can run it
> and see what it does.
C-x r d
--
http://mail.python.org/mailman/listinfo/python-list
lass().trace('Using ClassDefaultTracer')
> File "foo.py", line 14, in trace
> self.InstanceTracer(fmt, *args)
> TypeError: unbound method DefaultTracer() must be called with MyClass
> instance as first argument (got str instance instead)
Unfortunately you'
$ python foo.py
> in DefaultTracer Testing at first
> in myTracer Testing at first
> Traceback (most recent call last):
> File "foo.py", line 20, in
> MyClass().trace('Using ClassDefaultTracer')
> File "foo.py", line 14, in trace
> self.InstanceTr
lassDefaultTracer')
File "foo.py", line 14, in trace
self.InstanceTracer(fmt, *args)
TypeError: unbound method DefaultTracer() must be called with MyClass
instance as first argument (got str instance instead)
Alternately, how can I achieve what I want, i.e. a class-wide default