On Wed, Feb 18, 2009 at 2:32 PM, Sebastian Rittau <srit...@jroger.in-berlin.de> wrote: > Hi! > > I am curious why the following will not work in Python: > > class foo(object): > def bar(self): > print self.attr > > class duck(object): > attr = 3.14 > > foo.bar(duck()) > > Is it a design decision that duck-typing self does not work or is there a > technical reason? From a practical standpoint it seems that being able to > duck-type self has merit, for example in unit testing complex classes.
Works for me in 3.0: Python 3.1a0 (py3k:69082, Jan 28 2009, 19:22:10) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class Foo(object): ... def bar(self): ... print(self.attr) ... >>> class Duck(object): ... attr = 3.14 ... >>> Foo.bar(Duck()) 3.14 Steve -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com