Is this horrible python code?
Michael George Lerner
mlerner at NO.SPAM.umich.PLEASE.edu
Wed Nov 5 17:43:35 EST 2003
Matthew <matthew at newsgroups.com> wrote:
> Hi,
> class call_me(object):
> def __init__(self, func, *args, **kw):
> self.func = func
> self.args = args
> self.kw = kw
> def __call__(self, *args, **kw):
> print "Execing..."
> return self.func(*self.args, **self.kw)
I'm not sure what you're trying to do with the rest of this, but
I think that your call_me class isn't doing what you want.
asteroids% python
Python 2.2 (#1, Feb 18 2002, 14:48:51) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> class A(object):
... def __init__(self,a):
... self.a = a
... def __call__(self,a):
... print "self.a is '%s' and a is '%s'" % (self.a,a)
...
>>> a = A('the first thing')
>>> a('the second thing')
self.a is 'the first thing' and a is 'the second thing'
>>>
so, i don't think your __call__ method will do what you
want. then again, i'm not exactly sure what you're trying to
do, so i can't figure out why you want to initialize things
your objects with func, args and kw *and* want to be able
to specify args and kw at call time.
-michael
More information about the Python-list
mailing list