[Chicago] constant length string manipulation

Lukasz Szybalski szybalski at gmail.com
Thu Nov 29 22:21:15 CET 2007


On Nov 29, 2007 3:06 PM, Lukasz Szybalski <szybalski at gmail.com> wrote:
> Hello,
> 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:
> a=b[:5]
> but if it is shorter
> a=b[:5] will put empty space at the beginning. I need to to put the
> space at the end.
>
> Is there another line of code that can do that without if statements?
>
> a='%5s' % b works the same as a=[b:5]
Actually I figured it out

 a='%-5s' % b will do just what i need

I would expect the first one to add empty space on the right but I guess not.

Lucas

>
>
> Any ideas?
> Lucas
>



-- 
-- 
Vim auto completion for python
http://lucasmanual.com/mywiki/FrontPage#head-8ce19b13e89893059e126b719bebe4ee32fe103c
TurboGears from start to finish:
http://www.lucasmanual.com/mywiki/TurboGears


More information about the Chicago mailing list