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)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to