Subclassing str object

Yaşar Arabacı yasar11732 at
Wed Aug 31 12:03:11 EDT 2011

I made a class like this (I shortened it just to show the point), what do
you think about it, do you think it is the python way of subclassing str (or
unicode in this case)

# -*- coding:utf-8 -*-class kelime(unicode):

    def __init__(self,sozcuk):
        self._sozcuk = sozcuk

    def __getattribute__(self, isim):
        att = super(kelime, self).__getattribute__(isim)

        if not callable(att):
            return att

        def sonra_cagir(*args, **kwargs):
            sonuc = att(*args, **kwargs)
            if isinstance(sonuc, basestring):
                return kelime(sonuc)
            return sonuc
        return sonra_cagir

    def cogul(self):

        for harf in reversed(self._sozcuk):
            if harf in kalin:
                return kelime(self._sozcuk + u"lar")
            elif harf in ince:
                return kelime(self._sozcuk + u"ler")

        return kelime(self._sozcuk + u"lar")

31 Ağustos 2011 14:43 tarihinde Yaşar Arabacı <yasar11732 at> yazdı:

> Hİ,
> I originally posted my question to here:
> Could you people please look at
> it and enlighten me a little bit? I would appreciate an answer either from
> here or at stackoverflow. Thanks in advance.
> --

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list