In article <[EMAIL PROTECTED]>,
 "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> You can even get closer, but it is NOT recommended
> 
> class foostr(str):
>      def plural (self):
>         if self.value[-1] in "sz":
>             return self.value + "es"
>         else:
>             return self.value + "s"
> 
> 
> #ugly hack
> setattr(__builtins__, "str", foostr)
> 
> print str("apple").plural()
> 
> # this however does not work
> # print "apple".plural()

It's fascinating that the setattr() works (and I agree with you that it's a 
bad idea), but given that it does work, why doesn't it work with a string 
literal?
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to