Why is “import *” bad?

后端 未结 12 2593
北恋
北恋 2020-11-21 06:26

It is recommended to not to use import * in Python.

Can anyone please share the reason for that, so that I can avoid it doing next time?

12条回答
  •  天命终不由人
    2020-11-21 06:53

    • Because it puts a lot of stuff into your namespace (might shadow some other object from previous import and you won't know about it).

    • Because you don't know exactly what is imported and can't easily find from which module a certain thing was imported (readability).

    • Because you can't use cool tools like pyflakes to statically detect errors in your code.

提交回复
热议问题