## 2.6.6 How do I call a method defined in a base class from a derived class that overrides it? 

Use the built-in$_{super()}$ function: 

classDerived (Base): def meth(self): super(Derived,self).meth() 

For version prior to 3.0, you may be using classic classes: For a class definition such as class Derived(Base): ... you can call method$_{meth()}$ defined in$_{Base}$ (or one of$_{Base}$’s base classes) as$_{Base.meth(self,}$ arguments...) . Here,$_{Base.meth}$is an unbound method, so you need to provide the$_{self}$argument. 

## 2.6.7 How can I organize my code to make it easier to change the base class? 

You could assign the base class to an alias and derive from the alias. Then all you have to change is the value assigned to the alias. Incidentally, this trick is also handy if you want to decide dynamically (e.g. depending on availability of resources) which base class to use. Example: 

classBase : ... BaseAlias =Base classDerived (BaseAlias): ... 

## 2.6.8 How do I create static class data and static class methods? 

Both static data and static methods (in the sense of C++ or Java) are supported in Python. 

For static data, simply define a class attribute. To assign a new value to the attribute, you have to explicitly use the class name in the assignment: 

classC : count=0 # number of times C.__init__ called def __init__ (self): C.count=C.count+1 def getcount(self): return C.count # or return self.count 

c.count also refers to$_{C.count}$ for any$_{c}$ such that$_{isinstance(c, C)}$ holds, unless overridden by$_{c}$ itself or by some class on the base-class search path from$_{c.__class__}$ back to$_{C}$. 

Caution: within a method of C, an assignment like$_{self.count = 42}$ creates a new and unrelated instance named “count” in$_{self}$’s own dict. Rebinding of a class-static data name must always specify the class whether inside a method or not: 

C.count=314 

Static methods are possible: 

classC : @staticmethod def static(arg1, arg2, arg3): # No 'self' parameter! ... 

