On Jul 11, 4:37 pm, Miles <[EMAIL PROTECTED]> wrote:

> Since strings are immutable, you need to override the __new__ method.
> Seehttp://www.python.org/download/releases/2.2.3/descrintro/#__new__

In case this isn't clear, here is how to do it:

In [1]: class MyString(str):
   ...:     def __new__(cls, value):
   ...:         return str.__new__(cls, value.lower())

In [2]: s = MyString('Hello World')

In [3]: s
Out[3]: 'hello world'

Note that this will not do fancy stuff like automatically call
__str__() methods.  If you want that, call str() first:

In [5]: class MyString(str):
   ...:     def __new__(cls, value):
   ...:         return str.__new__(cls, str(value).lower())

-Mike


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to