odd difference calling function from class or instance variable

Chris Angelico rosuav at gmail.com
Wed Aug 13 06:29:12 EDT 2014


On Wed, Aug 13, 2014 at 8:20 PM, GregS <not at my.real.address.com> wrote:
> Thanks to both of you for your incredibly prompt replies.  My homework for
> tonight is to digest the descriptor protocol...
>
> Peter, thanks for suggesting using staticmethod() to get the behaviour I was
> expecting.  I've only used staticmethod as a decorator before now.
>
> Chris, I agree that it's not every day you assign functions to class
> attributes, but it does have its uses (I won't bore you with mine).  Now
> that I know how it treads on the toes of Python's method magic, I can decide
> whether it's the best approach or not.

You seem to know what you're doing, which is a good start :) I aimed
my explanation a bit lower than your actual knowledge turns out to be,
so go ahead and do what you know you need to do. You're not treading
on Python's toes, here, but you're basically recreating some of what
Python normally does under the covers, so you'll need to actually
understand (instead of just treating as black-box magic) stuff like
the descriptor protocol.

ChrisA



More information about the Python-list mailing list