I’m currently writing code which pads a string with spaces, using Python’s format specification mini language:
print('''{user:<10}, you're welcome!'''.format(user='John Doe'))
The output is:
John Doe , you're welcome!
However, if user’s name is something like ‘Joooooooooooohn Doe’, I’d like to output:
Jooooooooo, you're welcome!
Is there a way to perform truncation AND padding using the format specification mini language?
Thanks!
From the page you linked to:
Precision is introduced by a period
So the correct format string is
{user:<10.10}.