What is the use of "from...import *" Statement in Python?

PythonServer Side ProgrammingProgramming

The "from module import *" statement is used to import all function from a Python module. For example, if you want to import all functions from math module and do not want to prefix "math." while calling them, you can do it as follows:

>>> from math import *
>>> sin(0)
>>> cos(0)

Note that for any reasonable large set of code, if you import * you will likely be cementing it into the module, unable to be removed. This is because it is difficult to determine what items used in the code are coming from 'module', making it easy to get to the point where you think you don't use the import any more but it's extremely difficult to be sure. It basically clutters the namespace and leaves you with lesser options to name things in your module.

Published on 19-Dec-2017 17:04:22