Currently have code that looks something like;
print \'{: <5}\'.format(\'test\')
This will pad my string with \' \' if it i
\' \'
You can use 5.5 to combine truncating and padding so that the output will always be of length of five:
5.5
'{:5.5}'.format('testsdf') # 'tests' '{:5.5}'.format('test') # 'test '
You could use str.ljust and slice the string:
str.ljust
>>> 'testsdf'.ljust(5)[:5] 'tests' >>> 'test'.ljust(5)[:5] 'test '