What are all the ways to import modules in Python?

前端 未结 4 1580
陌清茗
陌清茗 2020-12-19 16:51

I\'ve done some research, and I came across the following article: http://effbot.org/zone/import-confusion.htm. While this seems to be a great guide, it was written in 1999,

4条回答
  •  不知归路
    2020-12-19 17:36

    I think import as tuple would be much better for readability and Maximum Line Length(pep8)

    The import statement has two problems:

    • Long import statements can be difficult to write, requiring various contortions to fit Pythonic style guidelines.
    • Imports can be ambiguous in the face of packages; within a package, it's not clear whether import foo refers to a module within the package or some module outside the package.
    • golang language have the same thing for that

    so would more prefer import kinda this

    from package import (x, y)
    

    instead of this

    from authentication.views import SignupView, LoginView, VerificationView, SignupDetailView
    

    https://legacy.python.org/dev/peps/pep-0328/

提交回复
热议问题