Re: changing __call__ on demand

2005-02-14 Thread Steven Bethard
F. Petitjean wrote: Le Sun, 13 Feb 2005 13:19:03 -0500, Hans Nowak a écrit : Note that it works just fine if you don't use a new-style class: class Test: ... def __init__(self): ... self.__call__ = self.foobar ... def foobar(self, *args, **kwargs): ... print "Called with:",

Re: changing __call__ on demand

2005-02-14 Thread F. Petitjean
Le Sun, 13 Feb 2005 13:19:03 -0500, Hans Nowak a écrit : > Stefan Behnel wrote: >> Hi! >> >> This somewhat puzzles me: >> >> Python 2.4 (#1, Feb 3 2005, 16:47:05) >> [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >> .>>> c

Re: changing __call__ on demand

2005-02-14 Thread Hans Nowak
Stefan Behnel wrote: Hi! This somewhat puzzles me: Python 2.4 (#1, Feb 3 2005, 16:47:05) [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2 Type "help", "copyright", "credits" or "license" for more information. .>>> class test(object): ... def __init__(self): ... self.__call__ = self.__call1 ... d

Re: changing __call__ on demand

2005-02-14 Thread Michael Hoffman
Stefan Behnel wrote: Thanks for the quick answer. I didn't know they were class-level methods. Too bad. Guess I'll stick with indirection then. Here is one way of doing that indirection I just thought of--have the class __call__ attribute call on the instance __call__ attribute: >>> class MyClass(

Re: changing __call__ on demand

2005-02-13 Thread Alan McIntyre
Thanks; I didn't read close enough. :) -- Alan McIntyre ESRG LLC http://www.esrgtech.com Michael Hoffman wrote: Alan McIntyre wrote: >>>class test(object): ...def __call1(self): ...print 1 ...__call__ = __call1 Is that what you were looking for? That still only allows him to have o

Re: changing __call__ on demand

2005-02-13 Thread Kent Johnson
Stefan Behnel wrote: Hi! This somewhat puzzles me: Python 2.4 (#1, Feb 3 2005, 16:47:05) [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2 Type "help", "copyright", "credits" or "license" for more information. .>>> class test(object): ... def __init__(self): ... self.__call__ = self.__call1 ... d

Re: changing __call__ on demand

2005-02-13 Thread Steven Bethard
Stefan Behnel wrote: Is there a way to change __call__ after class creation? Check out this thread on the topic: http://mail.python.org/pipermail/python-list/2004-January/203142.html Basically, the answer is no -- at least not on a per-instance basis. You can try something like: py> class Test(ob

Re: changing __call__ on demand

2005-02-13 Thread Stefan Behnel
Michael Hoffman schrieb: __call__, like __getitem__, and __getattr__ is called on the class object, not the instance object. So, no, not as far as I am aware, without using metaclass trickery. The simplest option IMO is to use another level of indirection as you suggest. Thanks for the quick answer

Re: changing __call__ on demand

2005-02-13 Thread Michael Hoffman
Alan McIntyre wrote: >>>class test(object): ...def __call1(self): ...print 1 ...__call__ = __call1 Is that what you were looking for? That still only allows him to have one call function per class. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list

Re: changing __call__ on demand

2005-02-13 Thread Michael Hoffman
Stefan Behnel wrote: Is there a way to change __call__ after class creation? __call__, like __getitem__, and __getattr__ is called on the class object, not the instance object. So, no, not as far as I am aware, without using metaclass trickery. The simplest option IMO is to use another level of ind

Re: changing __call__ on demand

2005-02-13 Thread Alan McIntyre
I tried this: >>>class test(object): ... def __call1(self): ... print 1 ... __call__ = __call1 ... >>>t = test() >>>t() 1 >>> Is that what you were looking for? -- Alan McIntyre ESRG LLC http://www.esrgtech.com Stefan Behnel wrote: Hi! This somewhat puzzles me: Python 2.4 (#1, F

changing __call__ on demand

2005-02-13 Thread Stefan Behnel
Hi! This somewhat puzzles me: Python 2.4 (#1, Feb 3 2005, 16:47:05) [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2 Type "help", "copyright", "credits" or "license" for more information. .>>> class test(object): ... def __init__(self): ... self.__call__ = self.__call1 ... def __call1(self): ...