Nail
14 Jun 2025

Should I avoid using from ... * imports in Python?

I was taught by co-workers not to use asterisk imports in Python.

from math import *

result = sqrt(16) + cos(0)

In this case, we can use all functions in math standard library. “So nice, because I can omit library names!”, I thought before the errors happened.

The “logger” file is usually imported to many files in our project. Someone imported “log” from logger library and I wrote the code like above example. Then “log” didn’t work properly.

I learn not to use asterisk imports and import a few functions specifically.