中学理科1625756 views
英語606840 views
高校国語785262 views
ヒストリア282760 views
MathPython489968 views
教育148774 views
高校日本史189759 views
高校倫理1432233 views
世界の国559994 views
数学講師2847003 views

Nail

Help
Tools

English

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.