是否有推荐的多行导入格式? [英] Is there a recommended format for multi-line imports?
本文介绍了是否有推荐的多行导入格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经阅读了在 python 中编码多行导入的三种方法
I have read there are three ways for coding multi-line imports in python
带斜线:
from Tkinter import Tk, Frame, Button, Entry, Canvas, Text, \
LEFT, DISABLED, NORMAL, RIDGE, END
重复句子:
from Tkinter import Tk, Frame, Button, Entry, Canvas, Text
from Tkinter import LEFT, DISABLED, NORMAL, RIDGE, END
带括号:
from Tkinter import (Tk, Frame, Button, Entry, Canvas, Text,
LEFT, DISABLED, NORMAL, RIDGE, END)
有没有推荐的格式或更优雅的方式来处理这个语句?
Is there a recomended format or a more elegant way for this statements?
推荐答案
我个人在导入多个组件时使用括号并按字母顺序排序.像这样:
Personally I go with parentheses when importing more than one component and sort them alphabetically. Like so:
from Tkinter import (
Button,
Canvas,
DISABLED,
END,
Entry,
Frame,
LEFT,
NORMAL,
RIDGE,
Text,
Tk,
)
这有一个额外的优势,可以轻松查看在每个提交或 PR 中添加/删除了哪些组件.
This has the added advantage of easily seeing what components have been added / removed in each commit or PR.
总的来说,虽然这是个人喜好,但我建议您选择最适合您的东西.
Overall though it's a personal preference and I would advise you to go with whatever looks best to you.
这篇关于是否有推荐的多行导入格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文