Reputation: 52850
xxxxxxxxxxxxx1.11xxxxxxxxxx1.11xxxxxxxxxxx1.11
xxxxxxxxxxxxx1.11xxxxxxxxxx1.11xxxxxxxxxx11.11
N.b. the numbers could be larger but not greater than 10 signs. The linewise count 46 (=17+14+15)
is constant.
[Update] Notice that I am using Python 2.6.5 so getting error ValueError: zero length field name in format
with suggestions.
Upvotes: 1
Views: 461
Reputation: 8951
You don't need a module or library to do this, use string formatting. To avoid the ValueError
, specify what index your parameter is in the supplied values:
"{0:>17}".format(11.1)
Upvotes: 2
Reputation: 52850
Someone commented the right answer but removed it so I will post it here. I will remove it if s/he post it so the credits go to the right person.
('%17.2f%14.2f%15.2f' % (1.11, 1.11, 11.11))
Upvotes: 1
Reputation: 188114
String formatting is built-in:
Examples for Python 2.7/3.1
>>> '{:x>17}'.format(s)
'xxxxxxxxxxxx11.11'
>>> '{:x>17}{:x>14}{:x>15}'.format(11.1, 11.1, 11.1)
'xxxxxxxxxxxxx11.1xxxxxxxxxx11.1xxxxxxxxxxx11.1'
Upvotes: 2