Python: Why should 'from <module> import *' be prohibited?

Viewed 33711

If you happen to have

from <module> import *

in the middle of your program (or module), you would get the warning:

/tmp/foo:100: SyntaxWarning: import * only allowed at module level

I understand why import * is discouraged in general (namespace invisibility), but there are many situations where it would prove convenient, especially where code is not shared with anyone.

So, can anyone explain precisely in detail why from <module> import * should be prohibited in all possible cases?

6 Answers
Related