'from X import a' versus 'import X; X.a'

后端 未结 9 2007

I\'ve seen some Python programmers use the following style fairly consistently (we\'ll call it style 1):

import some_module
# Use some_module.some_identifier in          


        
9条回答
  •  别那么骄傲
    2021-02-04 15:13

    With the existence of the following syntax:

    import some_other_module as some_module
    

    the maintainability argument of style 2 is no longer relevant.

    I tend to use style 1. Normally, I find that I explicitly reference the imported package name only a few times in a typical Python program. Everything else is methods on the object, which of course don't need to reference the imported package.

提交回复
热议问题