Importing all names from a module

suggest change
from 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 will import all names defined in the math module into the global namespace, other than names that begin with an underscore (which indicates that the writer feels that it is for internal use only).

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's the square root of {}.".format(num))

sqrt(4)
# Output: I don't know what's the square root of 4.

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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents