What does self(variable) do in Python?
I'm trying to understand someone else's code in Python and I stumbled across a line I don't quite understand and which I can't find on the internet:
x=self(k)

with k being a torch-array.
I know what self.something does but I haven't seen self(something) before.

self, for these purposes, is just a variable like any other, and when we call a variable with parentheses, it invokes the __call__ magic method. So
x = self(k)

is effectively a shortcut for
x = self.__call__(k)


Footnote: I say &quot;effectively&quot;, because it's really more like
x = type(self).__call__(self, k)

due to the way magic methods work. This difference shouldn't matter unless you're doing funny things with singleton objects, though.
