String has an 'ljust' method that left-justifies the string in a column of
a given length, so you could do:

some_string = something.ljust(len(some_other_string))

(I'm on the train so I can't run this to check, but I'm pretty sure that's
correct).

Cheers,
Tom
On 13 May 2014 07:27, "David Crisp" <[email protected]> wrote:

> I need to create a string that has a variable length of padding and im not
> sure how to do it.
>
> For instance
>
> some_string = ("{something:<40}".format(something = somethingelse))
>
> will give me a 40 space padded display of something
>
>
> What if, after a little bit of string concatination (for want of a abetter
> word)  I want to do the following:
>
> string_length = len(some_other_string)
>
> some_string = ("{something:<string_length}".format(something =
> somethingelse))
>
> When I do this I get a ValueError: Invalid format specifier.
>
> IS there a clean and neat way of doing the above?
>
> Regards,
> David Crisp
>
>
>
>
> _______________________________________________
> melbourne-pug mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/melbourne-pug
>
_______________________________________________
melbourne-pug mailing list
[email protected]
https://mail.python.org/mailman/listinfo/melbourne-pug

Reply via email to