我想写打印出输入文件的功能:如看到左侧的“table.txt”:打印内容转换成表格形式
成格式如图在图像的右侧。
我曾尝试:
f = open("table1.txt",'r')
for aline in f:
values = aline.split(',')
print('Team:',values[0],', Points:',values[1],', Diff:',int(values[2])-int(values[3]),'Goals:',values[2])
f.close()
,输出:
Team: FC Ingolstadt 04 , Points: 13 , Diff: -2 Goals: 4
Team: Hamburg , Points: 9 , Diff: -2 Goals: 8
Team: SV Darmstadt 98 , Points: 9 , Diff: -1 Goals: 8
Team: Mainz , Points: 9 , Diff: -3 Goals: 6
Team: FC Augsburg , Points: 4 , Diff: -5 Goals: 7
Team: Werder Bremen , Points: 6 , Diff: -5 Goals: 7
Team: Borussia Moenchengladbach , Points: 6 , Diff: -6 Goals: 9
Team: Hoffenheim , Points: 5 , Diff: -4 Goals: 8
Team: VfB Stuttgart , Points: 4 , Diff: -8 Goals: 9
Team: Schalke 04 , Points: 16 , Diff: 11 Goals: 14
Team: Hannover 96 , Points: 2 , Diff: -12 Goals: 6
Team: Borrusia Dortmund , Points: 16 , Diff: 11 Goals: 15
Team: Bayern Munich , Points: 18 , Diff: 16 Goals: 18
Team: Bayer Leverkusen , Points: 14 , Diff: 3 Goals: 11
Team: Eintracht Frankfurt , Points: 9 , Diff: 4 Goals: 13
Team: Hertha BSC Berlin , Points: 14 , Diff: 1 Goals: 5
Team: 1. FC Cologne , Points: 13 , Diff: 0 Goals: 10
Team: VfB Wolfsburg , Points: 14 , Diff: 4 Goals: 10
但你如何打印值,使行编号,列有标题:“队,积分,差异,目标“?
你可以上传示例文本文件 –
这已经在[stackoverflow](http://stackoverflow.com/questions/9535954/python-printing-lists-as-tabular-data)之前回答。 – CodeMonkey
尚未回答。 – Newbie