From: jkraai at murl.com (jkraai at murl.com)
Date: Thu, 29 Apr 1999 19:31:00 GMT
Subject: padding strings
Message-ID: <009301be9276$e20531a0$8b7125a6@cpda6686.mcit.com>
X-UID: 726                                                  

padchar = ' '
N = 50

str = 'I need to be padded'
padded = (str+padchar*N)[:N]

print '>'+padded+'<'
print 'len:',len(padded)

--jim

-----Original Message-----
From: Roy Smith <roy at endeavor.med.nyu.edu>
Newsgroups: comp.lang.python
To: python-list at cwi.nl <python-list at cwi.nl>
Date: Thursday, April 29, 1999 2:01 PM
Subject: padding strings


>Given a string, I want to generate another string which is exactly N
>characters long.  If the first string is less than N, I want to blank-pad
>it.  If the first string is greater than N, I want to truncate it.
>
>What's the most straight-forward way to do that?
>
>-- 
>Roy Smith <roy at popmail.med.nyu.edu>
>New York University School of Medicine
>





