[Chicago] constant length string manipulation
carl at personnelware.com
Thu Nov 29 22:38:31 CET 2007
Lukasz Szybalski wrote:
> Is there a string function in python that does the following:
> I need a string of length 5 char, and I will pass a longer and shorter
> string but I always need to get string of length 5.
> If my string is longer its easy:
> but if it is shorter
> a=b[:5] will put empty space at the beginning.
um, no it won't.
> I need to to put the
> space at the end.
> Is there another line of code that can do that without if statements?
>>> ('%s '%'abc')[:5]
>>> ('%s '%'abcdef')[:5]
> a='%5s' % b works the same as a=[b:5]
um, no it doesn't, even with the typo corrected.
I suggest using copy/paste when copying code. (or anything else I guess.)
and including the output from your tests.
More information about the Chicago