This is closely related to: Importing modules in Python - best practice , but the following case is not really discussed in details.
If we have a module coordinates that defines one class Coordinates and several utility function to work with the Coordinates type. What is the recommended way to do the following two things:
- Import the complete
coordinatesmodule - While binding
Coordinatestocoordinates.Coordinates
The two options I see for now:
import coordinates
from coordinates import Coordinates
But that seems a bit odd, on the other hand the other solution I see doesn't seem very clean either:
import coordinates
Coordinates = coordinates.Coordinates
Which one of this two is the most commonly used or the prefered way of doing this? Or maybe both of these shouldn't be used, in which case what would be a better solution?
Another option I'm considering but that I would prefer to avoid is one proposed in the referenced question: import coordinates as crd and then simply use crd.Coordinates instead of Coordinates. The reason why I want to avoid this is because it would make my code less readable, in particular when I use a function from the coordinates module. To this alternative I would probably prefer to simply call coordinates.Coordinates even if that looks redundant.
I've also considered making my module callable to make coordinates() to automatically call Coordinates() but I'm not really sure it's really a good solution either (and I'm not sure how to handle the documentation in such case).