Why is “import *” bad?

后端 未结 12 2463
北恋
北恋 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:33

    Say you have the following code in a module called foo:

    import ElementTree as etree
    

    and then in your own module you have:

    from lxml import etree
    from foo import *
    

    You now have a difficult-to-debug module that looks like it has lxml's etree in it, but really has ElementTree instead.

提交回复
热议问题