Importing all names from a module
suggest changefrom module_name import *
For example:
from math import *
sqrt(2) # instead of math.sqrt(2)
ceil(2.7) # instead of math.ceil(2.7)
This imports the public names from math into the global namespace. Names that begin with an underscore are skipped. If a module sets __all__, only the names listed there are imported.
Warning: If a function with the same name was already defined or imported, it will be overwritten. Almost always importing only specific names from math import sqrt, ceil is the recommended way:
def sqrt(num):
print("I don't know what the square root of {} is.".format(num))
sqrt(4)
# Output: I don't know what the square root of 4 is.
from math import *
sqrt(4)
# Output: 2.0
Starred imports are only allowed at the module level. Attempts to perform them in class or function definitions result in a SyntaxError.
def f():
from math import *
and
class A:
from math import *
both fail with:
SyntaxError: import * only allowed at module level
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents