Reputation: 25641
I don't know if it's possible with common string formatting or advanced string formatting, so thought to ask...
I have this simplified snippet:
>>> s = 'some string'
>>> y = 10
>>> '<td>%s</td><td>%4d</td>' % (s, y)
'<td>some string</td><td> 10</td>'
I want to pad numeric cell with
as my html backend doesn't accept text aligning.
Is there easy way to format numerical value with
instead empty space?
Upvotes: 1
Views: 276
Reputation: 994947
You could use something like:
"%s%d" % (" " * (4 - len(str(y))), y)
Upvotes: 2