There are several ways we can import and use the resources defined in a module. Taking the calculator module we defined previously, you have already seen one way to go about it, which is importing the whole module by using the import keyword and then calling a resource inside it by using the dot (.) notation, like so:
>>> import calculator >>> calculator.add(8, 9) 17
Another way of accessing a module's resources is to use the from…import… syntax:
>>> from calculator import * >>> add(8, 9) 17
Note that the * in the preceding example tells Python to import everything in the module named calculator. We can then use any resource defined in the calculator module by referring to the resource name (in our case, the add function) directly. You should note that using * is not a good practice. You should always strive to import exactly what you need.
What if you want to only import a few resources from the module? In that case, you can name...