I’m trying to translate some python code to scala code. So I’m a total noob in Python.
But why do some classes have object as a parameter but never explicitly use it? What’s the reasoning for having it as a parameter in the first place?
Example:
class Table(object)
Thank you for your time.
In Python2 this declares
Tableto be a new-style class (as opposed to “classic” class).In Python3 all classes are new-style classes, so this is no longer necessary.
New style classes have a few special attributes that classic classes lack.
Also, properties and super do not work with classic classes.
In Python2 it is a good idea to make all classes new-style classes. (Though a lot of classes in the standard library are still classic classes, for the sake of backward-compatibility.)
In general, in a statement such as
Foois being declared as a class inheriting from base classesBase1andBase2.objectis the mother of all classes in Python. It is a new-style class, so inheriting fromobjectmakesTablea new-style class.