Roy Smith wrote:
> 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"
>>els
Negroup wrote:
> Hi all.
> I'm writing a simple Python module containing functions to process
> strings in various ways. Actually it works importing the module that
> contains the function I'm interested in, and calling
> my_module.my_function('mystring').
>
> I was just asking if it is possible t
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 se
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()
#
[EMAIL PROTECTED] (Negroup) wrote:
> I was just asking if it is possible to "extend" string objects'
> behaviour so that it becomes possible to invoke something like
> 'anystring'.my_method().
You can't quite do that, but you can get close. You can define your own
class which inherits from str,