从Python的内置类创建的子类不好吗?

我有几种情况,可以将内置类用作父类,简单示例:

class CustomStr(str):
    def __init__(self, input_str):
        self = input_str

    def e_is_here(self):
        if 'e' in self:
            return True
        else:
            return False

hw = CustomStr('Hello World!')
print(hw.e_is_here())

Why it is good for me - I can still use built-in methods (append, in, sort, etc.) and add several custom methods. I don't need to create class with only one attribute and get 'more complicated' version like hw.string.e_is_here() instead.

但是对于高级项目来说可以接受吗?它对其他人可读吗,或者我应该改用1st lvl函数?

评论