假设我有这两个列表:
column1 = ["Attribute:","Virtual machine:","Troll:"]
column2 = ["A value associated with an object which is referenced by name using dotted expressions. For example, if an object o has an attribute a it would be referenced as o.a.",
"A computer defined entirely in software. Python's virtual machine executes the bytecode emitted by the bytecode compiler.",
"Someone who posts inflammatory, extraneous, or off-topic messages in an online community, such as a forum, chat room, or blog, with the primary intent of provoking readers into an emotional response or of otherwise disrupting normal on-topic discussion."]
这段代码:
for c1, c2 in zip(column1, column2):
print "%-16s %s" % (c1, c2)
输出此文本:
Attribute: A value associated with an object which is referenced by name u
sing dotted expressions. For example, if an object o has an attribute a it would
be referenced as o.a.
Virtual machine: A computer defined entirely in software. Python's virtual machi
ne executes the bytecode emitted by the bytecode compiler.
Troll: Someone who posts inflammatory, extraneous, or off-topic messag
es in an online community, such as a forum, chat room, or blog, with the primary
intent of provoking readers into an emotional response or of otherwise disrupti
ng normal on-topic discussion.
虽然我想要这样:
Attribute: A value associated with an object which is referenced by name
using dotted expressions. For example, if an object o has an
attribute a it would be referenced as o.a.
Virtual machine: A computer defined entirely in software. Python's virtual
machine executes the bytecode emitted by the bytecode compiler.
Troll: Someone who posts inflammatory, extraneous, or off-topic
messages in an online community, such as a forum, chat room, or
blog, with the primary intent of provoking readers into an
emotional response or of otherwise disrupting normal on-topic
discussion.
对于任何终端尺寸,我如何获得此结果?(有人告诉我,克林特可能很容易做到这一点,有人做过吗?)
注意:一个单词在行尾不被切碎的要求对我来说只是次要的。最重要的要求是让列表中的每个字符串元素以与该column2
列表中每个元素的字符串开始处相同的水平间距继续。