Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 1
    or type(self).BAR Commented May 28, 2018 at 13:24
  • I then expect your code to use self.__class__.method(self) instead of self.method() ?-) More seriously: while the first two paragraphs are perfect, the third one is just not the pythonic way. Pythoneers know that an attribute not resolved on the instance will be looked up on the class so self.BAR is perfectly clear. Commented May 28, 2018 at 13:25
  • @brunodesthuilliers The question was specifically about class variables, rather than methods. Methods already resolve via the MRO and it's unlikely that you'll be redefining methods at runtime beyond simple inherritance. Commented May 28, 2018 at 13:28
  • 1
    @solidpixel methods ARE class variables. Commented May 28, 2018 at 13:30
  • 1
    Sure, from a purely technical point of view they are. From a coding style point of view it is actually rare that you actually dynamically write over an existing bound method at runtime (it's very bad practise), whereas writable "normal" class variables can be reasonably common in real code. Commented May 28, 2018 at 13:33