trouble subclassing str

Paul McGuire ptmcg at austin.rr.com
Fri Jun 24 00:27:20 EDT 2005


Dang, that class should be:

class PaddedStr(str):
    def __new__(cls,s,l,padc=' '):
        if l > len(s):
            s2 = "%s%s" % (s,padc*(l-len(s)))
            return str.__new__(cls,s2)
        else: 
            return str.__new__(cls,s) 

-- Paul




More information about the Python-list mailing list