DEV Community

Discussion on: Quick Intro to Python Modules

Collapse
 
patryktech profile image
Patryk

[import *] is bad practice because the code is inefficient because we import everything. Also, we may have clashing names since we import more members than we’re supposed to.

I think it's bad practice because of the second part (name collisions), not really because "importing everything is inefficient."

AFAIK, there is no difference in doing import random and from random import * in terms of performance. It's just a different namespace.

As per the python documentation:

Note that in general the practice of importing * from a module or package is frowned upon, since it often causes poorly readable code. However, it is okay to use it to save typing in interactive sessions.

It doesn't mention performance, only readability.

Rest of the article looks good, though. Thanks for sharing.

Collapse
 
aumayeung profile image
John Au-Yeung

Thanks. I made the correction.