Wrapping paper, anyone ?
simon
pianomaestro at gmail.com
Thu Dec 17 01:04:34 EST 2009
On Dec 17, 2:18 am, Peter Otten <__pete... at web.de> wrote:
> simon wrote:
> > On Dec 16, 9:00 pm, Peter Otten <__pete... at web.de> wrote:
> >> simon wrote:
>
> >> Nice :)
>
> >> --- stars.py 2009-12-16 10:52:49.553505036 +0100
> >> +++ stars_fixed.py 2009-12-16 10:53:32.545786454 +0100
> >> @@ -48,7 +48,9 @@
> >> def __init__(self):
> >> self.calls = []
>
> >> - __getattr__ = ScribeCall
> >> + def __getattr__(self, name):
> >> + return ScribeCall(self, name)
> >> +
> >> def run(self, ctx):
> >> for call in self.calls:
> >> #print "ctx.%s(%s)" % (call.name, ', '.join(str(x) for x in
> >> call.args))
>
> >> Peter
>
> > Oh.. I'm on py2.5.. does this not work for you ?
>
> You mean 2.4? Here's a little demo:
>
> $ cat scribecall.py
> class ScribeCall(object):
> def __init__(self, scribe, name):
> print "init", scribe, name
> def __call__(self, *args, **kw):
> print "call", args, kw
>
> class Scribe(object):
> __getattr__ = ScribeCall
>
> if __name__ == "__main__":
> scribe = Scribe()
> scribe.yadda(42)
>
> $ python2.4 scribecall.py
> init <__main__.Scribe object at 0x7fc87b9a1450> yadda
> call (42,) {}
>
> $ python2.5 scribecall.py
> Traceback (most recent call last):
> File "scribecall.py", line 12, in <module>
> scribe.yadda(42)
> TypeError: __init__() takes exactly 3 arguments (2 given)
>
> $ python2.5 -V
> Python 2.5.4
>
> $ python2.6 scribecall.py
> Traceback (most recent call last):
> File "scribecall.py", line 12, in <module>
> scribe.yadda(42)
> TypeError: __init__() takes exactly 3 arguments (2 given)
>
> Peter
Oh wow, it works on python 2.5.2 !
Simon.
More information about the Python-list
mailing list