干线长字符串格式 - Python的
问题描述:
我打印此表中的Python:使用这种格式的代码行干线长字符串格式 - Python的
NOMBRE POBLACIÓN ENFERMOS SANOS RATA Chile 17000000 0 17000000 0.00 Hanslandia 2000000 2000000 0 1.00 Bastiland 4000000 0 4000000 -0.01 Peru 31000000 0 31000000 0.00 Bolivia 10000000 10000000 0 1.00 Argentina 43000000 0 43000000 0.00 Henryboysnia 4200000 4200000 0 1.00 Inglaterra 51000000 0 51000000 0.00 Dondeeldiabloperdioelponcho 500000 0 500000 0.00 Laquebradelaji 11000000 11000000 0 1.00 Uruguay 2000000 0 2000000 0.00 Paraguay 4000000 0 4000000 0.00 Suriname 500000 0 500000 0.00 Venezuela 31000000 31000000 0 1.00 Fantasilandia 3000000 0 3000000 -0.01 USA 300000000 0 3000000000.00 NotUSA 20000000 0 20000000 -0.01 Mexico 127000000 0 1270000000.00 Happyland 5000000 0 5000000 -0.01 UvuvwevweOnyetenyevweUgwembubwemOssas13000000 0 13000000 -0.01
:
print("{0: ^20}{1: ^9.0f}{2: ^9.0f}{3: ^9.0f}{4: ^5.2f}".format(mundo[country].name,mundo[country].inhabitants,mundo[country].sick[i],mundo[country].healthy[i],mundo[country].rata[i]))
的事情是,有此字符串vuvwevweOnyetenyevweUgwembubwemOssas
时间太长并使得其他列看到所有无序。我已经研究和,按说,如果我做{0:. ^20}
,该.
将字符串主干为20个字符,但我所得到的,当我拿到那点是左对齐的第一列。任何想法,为什么,我该怎么办呢?
[Python的截断长字符串](https://stackoverflow.com/q/2872512/669576) –