Just curious: Is there a way to (ab)use the string.formatmethod without any arguments?
Say I want a string like this:
'foo bar ' # Desired string
I could create a template string like:
'foo{:3}bar{:4}'
And then use it with dummy parameters like:
>>> 'foo{:3}bar{:4}'.format('', '')
'foo bar '
>>> 'foo{:3}bar{:4}'.format(*' ')
'foo bar '
Since omitting parameters will give this error:
>>> 'foo{:3}bar{:4}'.format()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: tuple index out of range
I can even create a single dummy variable like:
'foo{s:3}bar{s:4}'.format(s='')
But is there an even more elegant way to create parameterized strings using string.format?
'foo{}bar{}'.format(' '*3, ' '*4)?'{:<6}{:<7}'.format('foo', 'bar')f'foo{" "*3}bar{" "*4}'.