Hello,
I encountered the following sentence and code snippet from the mission about visualizing geographic data:
We can pass in a list of latitude and longitude values into the basemap instance and it will return back converted lists of longitude and latitude values using the projection.
x, y = m(longitudes, latitudes)
In the code snippet above, m is an instance of the basemap class. Looking at this I was confused about how one can ‘call’ an instance. From the OOP mission, I knew we could call functions, methods, and classes, but calling an instance didn’t make sense to me at first.
Googling this out I found that, similar to the special __init__
method that can exist in class definitions, there can also be a special __call__
method inside a class definition to handle instance calls. You pass arguments into an instance call, similar to a function or method. So if you run x, y = m(longitudes, latitudes)
, what actually gets executed under the hood is x, y = m.__call__(longitudes, latitudes)
. So an instance, like a function, method, or class is callable, that is, anything you can call , using parenthesis, and possibly passing arguments.
Providing a brief explanation about the instance.__call__
method and the associated callable concept, while introducing basemap, would provide more clarity to the students, and reinforce their learning of OOP concepts (by the way, the OOP mission is awesome !).
DQ team: Can you please consider this feedback?
Thank you.