[IronPython] Duck typing / builders

Simon Dahlbacka simon.dahlbacka at gmail.com
Wed Dec 13 22:36:02 CET 2006


..you want to look at __getattr__ and/or __getattribute__

On 12/13/06, Hamilton Verissimo <hammett at castlestronghold.com> wrote:
>
> Appologies for not being specific. I was really looking forward to the
> ability to allow invocations on undeclared methods. I'm not fluent in
> python, but I think __call__ is the way to support that, for instance:
>
> class Proxy(object):
>
>   def __call__(self, method, arguments):
>     record(method, arguments)
>
> In Ruby I'd use method_missing in a similar fashion.
>
> Thanks
>
> On 12/13/06, Dino Viehland <dinov at exchange.microsoft.com> wrote:
> > Yes, IronPython is completely duck typed, but I'm not certain how your
> x.bar & x.foo ties into that.
> >
> > It almost sounds like you want foo and bar to be properties.  You can do
> that with:
> >
> > class baz(object):
> >         @property
> >         def foo(self):
> >                 print "I've been called"
> >                 return 42
> >         @property
> >         def bar(self):
> >                 print "Me too!"
> >                 return 23
> >
> > a = baz()
> > a.bar
> >
> > which will print "Me too!" and return 23.  You can then also do anything
> with this object from there, eg:
> >
> > a.xyz = 23
> >
> > Traditionally duck typing refers to "if it looks like a duck, and quacks
> like a duck, it's a duck".  That's more like:
> >
> > class balloon(object):
> >         def blowup(self):
> >                 print 'inflating balloon'
> >
> > class bomb(object):
> >         def blowup(self):
> >                 print 'exploding'
> >
> > def InflateIt(obj):
> >         obj.blowup()
> >
> > InflateIt(bomb())
> >         Or
> > InflateIt(balloon())
> >
> > Both call the blowup method disregarding the fact that blowing up a
> ballon and blowing up a bomb are two rather different concepts - but they
> both look like the same duck.
> >
> >
> > -----Original Message-----
> > From: users-bounces at lists.ironpython.com [mailto:
> users-bounces at lists.ironpython.com] On Behalf Of Hamilton Verissimo
> > Sent: Wednesday, December 13, 2006 11:19 AM
> > To: users at lists.ironpython.com
> > Subject: [IronPython] Duck typing / builders
> >
> > Does IronPython support any form of duck typing? Ideally I want
> somethign like
> >
> > x.foo
> > x.bar
> >
> > And record this invocations to generate, well, other things.
> >
> > Thanks
> >
> > --
> > Cheers,
> > hamilton verissimo
> > hammett at castlestronghold.com
> > http://www.castlestronghold.com/
> > _______________________________________________
> > users mailing list
> > users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> > _______________________________________________
> > users mailing list
> > users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
>
>
> --
> Cheers,
> hamilton verissimo
> hammett at castlestronghold.com
> http://www.castlestronghold.com/
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20061213/4a11d4b4/attachment.html>


More information about the Ironpython-users mailing list