Use 'import module' or 'from module import'?

前端 未结 19 2578
一向
一向 2020-11-21 07:47

I\'ve tried to find a comprehensive guide on whether it is best to use import module or from module import. I\'ve just started with Python and I\'m

19条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-21 08:05

    since many people answered here but i am just trying my best :)

    1. import module is best when you don't know which item you have to import from module. In this way it may be difficult to debug when problem raises because you don't know which item have problem.

    2. form module import is best when you know which item you require to import and also helpful in more controlling using importing specific item according to your need. Using this way debugging may be easy because you know which item you imported.

提交回复
热议问题