Duncan Booth wrote:
Diez B. Roggisch wrote:
Duncan Booth wrote:
Bound methods get created whenever you reference a method of an
instance.

That did escape me so far - interesting. Why is it that way? I'd
expect that creating a bound method from the class and then storing it
in the objects dictionary is what happens.

If you had a class with 50,000 methods it could take quite a while to create instances, consider Zope as an example where every object acquires large numbers of methods most of which are completely irrelevant. Even outside Zope most objects never have all their methods called: dict, for example, has 38 methods but most of them get little or no use.

So why couldn't bound methods be created like lazy properties:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/363602

So that they're not created at instance creation time, but they're only created once, when first accessed?

Not that I've ever had any problems with the speed or memory usage of bound methods -- I'm just curious about the design decision.

STeVe
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to