Subclassing str object

Yaşar Arabacı yasar11732 at gmail.com
Wed Aug 31 18:03:11 CEST 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 gmail.com> yazdı:

> Hİ,
>
> I originally posted my question to here:
> http://stackoverflow.com/q/7255655/886669 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.
>
> --
> http://yasar.serveblog.net/
>
>


-- 
http://yasar.serveblog.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110831/a466e5ea/attachment.html>


More information about the Python-list mailing list