I am learning about what the super()
method does, and I came across the term temporary object
. I do not understand what it means. I've heard that it is an object that you are meant to throw away after a bit but I have no idea what that also means. So, what is a temporary object
?
Asked
Active
Viewed 80 times
0
-
Does this answer your question? [What does 'super' do in Python? - difference between super().\_\_init\_\_() and explicit superclass \_\_init\_\_()](https://stackoverflow.com/questions/222877/what-does-super-do-in-python-difference-between-super-init-and-expl) – Silvio Mayolo Sep 01 '22 at 00:49
-
"temporary" is a broad term. Lots of functions return values that, if you don't assign them to anything, are immediately deleted. That's pretty temporary. `super()` returns an object that looks like your class instance except that it figures out how to call methods in superclasses. Python is dynamic and method resolution can change, so one usually doesn't keep this object around in a variable. `super().whatever()` returns an object that is used to resolve "whatever" and then, since it wasn't saved in a variable, is deleted. – tdelaney Sep 01 '22 at 00:55
1 Answers
0
There's no technical jargon here. It means what it says, an object that exists for a short time and need not be preserved. Sometimes the context dictates the object is never actually assigned to a variable at all (e.g. super().ANYMETHOD
creates the super
object as a temporary solely to look up the method, then the super
instance is discarded), sometimes it has a name but is only used briefly, e.g. in the unPythonic variable swap technique to swap variables a
and b
:
t = a
a = b
b = t
t
is a temporary object. (For those unaware, the Pythonic swap is a, b = b, a
)

ShadowRanger
- 143,180
- 12
- 188
- 271