You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1022 B

From: paul at (Paul Prescod)
Date: Thu, 29 Apr 1999 19:00:33 GMT
Subject: padding strings
References: <>
Message-ID: <>
X-UID: 20
Roy Smith wrote:
> 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?
How about this:
def mypad( s, num ):
return string.ljust( s, num )[:num]
Paul Prescod - ISOGEN Consulting Engineer speaking for only himself
"Microsoft spokesman Ian Hatton admits that the Linux system would have
performed better had it been tuned."
"Future press releases on the issue will clearly state that the research
was sponsored by Microsoft."