jsString class

Subscriber123 subscriber123 at gmail.com
Mon Feb 26 13:58:48 EST 2007


Hi all,

Some of you may find this useful. It is a class I wrote that acts like the
way strings do in JavaScript. It is a little buggy, and not complete, but
could be useful.

class jsString:
    def __init__(self,string):
        if string.__class__ is list:
            print "list:",string
            self.list=string
        else:
            print "string:",string
            self.list=[string]
    def __add__(self,other):
        try:
            r=self.list[:-1]+[self.list[-1]+other]
        except:
            r=self.list+[other]
        return jsString(r)
    def __mul__(self,other):
        try:
            r=self.list[:-1]+[self.list[-1]*other]
        except:
            r=self.list*other
        return jsString(r)
    def __len__(self):
        return len(str(self))
    def __str__(self):
        r=""
        for obj in self.list:
            r+=str(obj)
        return r
    def __repr__(self):
        return str(self.list)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070226/71b4a4b4/attachment.html>


More information about the Python-list mailing list