class-attributes

Python inheritance Best way to merge info with parents

Python inheritance Best way to merge info with parents Question: Imagine we have a class Animal with a class attribute info, which is a dictionary. There is a class Frog which inherits from Animal and also has a class attribute info. But the attribute info of the Frog class must also include the Animal info. …

Total answers: 2

Python class inheritance: AttributeError: '[SubClass]' object has no attribute 'xxx'

Python class inheritance: AttributeError: '[SubClass]' object has no attribute 'xxx' Question: I have the following base class and subclass: class Event: def __init__(self, sr1=None, foobar=None): self.sr1 = sr1 self.foobar = foobar self.state = STATE_NON_EVENT # Event class wrappers to provide syntatic sugar class TypeTwoEvent(Event): def __init__(self, level=None): self.sr1 = level self.state = STATE_EVENT_TWO Further on …

Total answers: 5

How to document class attributes in Python?

How to document class attributes in Python? Question: I’m writing a lightweight class whose attributes are intended to be publicly accessible, and only sometimes overridden in specific instantiations. There’s no provision in the Python language for creating docstrings for class attributes, or any sort of attributes, for that matter. What is the expected and supported …

Total answers: 4