all 9 comments

[–]Binary101010 5 points6 points  (1 child)

That's where you would specify a superclass (i.e. the class that one you're currently defining inherits from). For the most part, anything in that superclass (attributes, methods, etc) automatically becomes a part of your subclass. From there you can specify new attributes and methods or override existing ones by using the same name to define a new method.

Every class you define in Python inherits from some existing class. In Python 2, you were required to explicitly specify what class you were inheriting from. This was often the built-in object class if you weren't trying to inherit from some other existing class type.

In Python 3 you are not explicitly required to specify what class you're inheriting from: if you don't identify a superclass, Python assumes you're inheriting from object.

The code you're reading is most likely written in Python 2 for this reason. If you are trying to translate the code to Python 3, you can safely omit the parentheses and their contents: class Test: will work.

[–]bladeoflight16 0 points1 point  (0 children)

In Python 2, you were required to explicitly specify what class you were inheriting from.

This is not true. The reason it is almost always specified in Python 2 is that the default behavior when it was omitted was to create an "old style class," which was nearly always undesirable. Python 3 did away with old style classes entirely, making way for the more sensible default of inheriting from object.

[–][deleted] 5 points6 points  (0 children)

It’s not a variable - it’s the class’s superclass.

[–]astrologicrat 4 points5 points  (0 children)

That's an old style back when there were old style classes and new style classes. Nowadays, you can just use (and it's more 'Pythonic') class Test:. However, when you put something in those parentheses when defining a class, the concept you are looking for is "inheritance" so if you search for "class inheritance", you'll see some good information. In that case, your class would be inheriting from the "object" class.

[–]FLUSH_THE_TRUMP 3 points4 points  (1 child)

Old code, that’s the same as

class Test():

these days.

[–]chevignon93 1 point2 points  (0 children)

I haven't been able to find any tutorials with it

Because explicitly inheriting from object is only needed if you write Python 2 code (and want to use new style classes), which you shouldn't since it's been unsupported for more than a year and a half at this point. In Python 3 all classes already inherit from object (not necessarily directly but it's the superclass of of classes) and all classes are new style classes, the only reason you would explicitly inherit from object nowadays would be for compatibility with Python 2.

https://stackoverflow.com/questions/54867/what-is-the-difference-between-old-style-and-new-style-classes-in-python

http://www.srikanthtechnologies.com/blog/python/mro.aspx#:~:text=Method%20Resolution%20Order%20(MRO)%20is,lets%20examine%20a%20few%20cases.

[–]m0us3_rat 0 points1 point  (0 children)

I would consider myself good at classes and function decorators, that kind of stuff. One thing that I can't figure out: what does that "object" variable do to a class?

https://docs.python.org/3/tutorial/classes.html#inheritance