[英]how to make a formated print of list with list within it in python
I have a class in python with 2 "main" strings and a list of strings in it with N size 我在python中有一个带有2个“主”字符串的类,其中有一个N大小的字符串列表
How can I "nicely" format the print of it so i can print the pain list and it will look normal. 我怎样才能“很好地”格式化它的打印内容,以便我可以打印痛苦列表,它看起来很正常。
The expected result is like: 预期结果如下:
entry 1 : string1 string 2 <br>
liststring1 liststring2 .... liststring n
entry 2 : string1 string 2 <br>
liststring1 liststring2 .... liststring n
.<br>
.<br>
.<br>
entry n : string1 string 2 <br>
liststring1 liststring2 .... liststring n
Let's presume your python class, Entry
, has the following member variables: 让我们假设您的python类
Entry
具有以下成员变量:
Entry.string1
Entry.string2
Entry.list_of_strings
Then to print a list_of_entries
: 然后打印一个
list_of_entries
:
>>> for entry in list_of_entries:
... print entry, " : ", entry.string1, entry.string2
... for s in entry:
... print s,
... print ""
>>> l
[[1, 2, 3], [1, 2, 3]]
>>> for entry in l:
... print entry, ":",
... for x in entry:
... print x,
... print
Notice the trailing commas in print
statements. 请注意
print
语句中的尾部逗号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.