Python ClassesΒΆ
Slackware prefers stability often over keeping necessarily up-to-date. An example of this is how even Slackware 13.37 is distributed with Python 2.6.x instead of 2.7. Yes you can install 2.7 and 3 along side of the 2.6 version but unless you’re a professional python developer, who needs three versions? I have python 3 installed simply to play with the future installation, but I never bothered installing 2.7 as well.
While working on something for fun, I noticed a large difference in python 2.6 and 3.0. In 2.6, if you declare a class, it does not assume that you inherit from the object class and then any subclasses of that class do not work. For example:
class A:
def foo(self):
print("Foo")
class B(A):
def foo(self):
super(B, self).foo()
print("Bar")
b = B()
b.foo()
Will not work in 2.6 but will in 3.0. For the above snippet to work in 2.6, you need to explicitly state that A is inheriting from object, i.e.
class A(object):
def foo(self):
print("Foo")
class B(A):
def foo(self):
super(B, self).foo()
print("Bar")
b = B()
b.foo()
Naturally, this will also work in sys.version_info > (2, 6).