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

后端 未结 9 2128

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:21

    I personally try not to mess too much with my namespace, so in most situations I just do

    import module  
    

    or import module as mod

    Only real diffrence is when I have a module with a single class that's used a lot. If I had sublclassed a list type to add some funcionality there, I'd use

    from SuperImprovedListOverloadedWithFeatures import NewLIst
    nl = NewList()
    

    etc.

提交回复
热议问题