Is there a recommended format for multi-line imports?

后端 未结 4 1276
灰色年华
灰色年华 2020-12-12 21:21

I have read there are three ways for coding multi-line imports in python

With slashes:

from Tkinter import Tk, Frame, Button, Entry, Canvas, Text, \\         


        
4条回答
  •  不思量自难忘°
    2020-12-12 22:09

    I would go with the parenthesis notation from the PEP328 with newlines added before and after parentheses:

    from Tkinter import (
        Tk, Frame, Button, Entry, Canvas, Text, 
        LEFT, DISABLED, NORMAL, RIDGE, END
    )
    

    This is the format which Django uses:

    from django.test.client import Client, RequestFactory
    from django.test.testcases import (
        LiveServerTestCase, SimpleTestCase, TestCase, TransactionTestCase,
        skipIfDBFeature, skipUnlessAnyDBFeature, skipUnlessDBFeature,
    )
    from django.test.utils import (
        ignore_warnings, modify_settings, override_settings,
        override_system_checks, tag,
    )
    

提交回复
热议问题