34 lines
1022 B
Plaintext
34 lines
1022 B
Plaintext
From: paul at prescod.net (Paul Prescod)
|
|
Date: Thu, 29 Apr 1999 19:00:33 GMT
|
|
Subject: padding strings
|
|
References: <roy-2904991402400001@qwerky.med.nyu.edu>
|
|
Message-ID: <3728AC50.9085F2C0@prescod.net>
|
|
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
|
|
http://itrc.uwaterloo.ca/~papresco
|
|
|
|
"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."
|
|
http://www.itweb.co.za/sections/enterprise/1999/9904221410.asp
|
|
|
|
|
|
|
|
|