[Patches] [Patch #100913] Optional pad character (or string) for rjust, ljust

noreply@sourceforge.net noreply@sourceforge.net
Wed, 26 Jul 2000 23:48:28 -0700


Patch #100913 has been updated. 

Project: 
Category: None
Status: Open
Summary: Optional pad character (or string) for rjust, ljust

Follow-Ups:

Date: 2000-Jul-17 04:45
By: effbot

Comment:
looks fine to me, but you should really change the
unicode string type too (unicodeobject.c)
-------------------------------------------------------

Date: 2000-Jul-17 04:55
By: twouters

Comment:
And don't forget Lib/UserString.py ! :-)
+1 on the patch, though. I always had a nagging feeling this needed fixing, but I've never used it myself, and I thought there was another way to go 'bout it.

-------------------------------------------------------

Date: 2000-Jul-25 07:45
By: jhylton

Comment:
Can you also add code to the test suite to exercise this feature? Look in Lib/test/string_tests.py

-------------------------------------------------------

Date: 2000-Jul-26 23:48
By: moshez

Comment:
The semantics for strings are a bit confusing, and I'm not sure it's worth the complexity. Also, doing it once for strings and once for unicode is a bit redundant, when you can do it in pure Python for both types with ease...wouldn't it be better to to have ljust and rjust (with optional padding) remain in the string module, and make them work on both regular and unicode strings by polymorphism.

def rjust(s, l, pad=' '):
    missing = l-len(s)
    if missing > 0:
        return s+(pad*missing)
    else:
        return s

def ljust(s, l, pad=' '):
    missing = l-len(s)
    if missing > 0:
        return (pad*missing)+s
    else:
        return s

(Or the other way around, could never tell the difference between left and right)

-------------------------------------------------------

-------------------------------------------------------
For more info, visit:

http://sourceforge.net/patch/?func=detailpatch&patch_id=100913&group_id=5470