Python Forum

Full Version: Different Ways to Import Modules
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good morning,

I'm not entirely sure I understand the reason to use the asterix when importing modules, or what its significance might be, or why you would use it.

For example, I think doing something like this would import the entire module

import math

x = math.pi

print(x)
and I think doing something like this would import the specific function from the module?

from math import pi as why

x = why

print(x)
My question is, I don't understand the asterix when its used like this

from math import *

x = pi

print(x)
It's a wildcard import. In the example, it will import all the math functions and classes. It is also bad practice to do wildcard imports.
And you should never use wildcard imports. Wildcard imports make it more difficult to know what names are imported from which modules, silently import names that might collide with variables/functions in your program or other modules imported using a wildcard