小编Ham*_*bad的帖子

实例方法不是从对象开始工作,而是从它的类中工作

这是我几年前开始使用Python编程以来最奇怪的错误.

首先,这些是我的课程(抱歉长代码):

class Quran(Iterable):

    def __init__(self):
        self.sourats = []

    def __iadd__(self, other):
        # There is some code here
        pass

    def __getitem__(self, sourat_num):
        if not (isinstance(sourat_num, int) or isinstance(sourat_num, slice)):
            raise TypeError('Indexing Quran can be done only using ints or slices')
        if isinstance(sourat_num, int):
            sourat_num -= 1
        else:
            sourat_num = slice(sourat_num.start - 1, sourat_num.stop)
        try:
            return self.sourats[sourat_num]
        except IndexError:
            return None

    def __len__(self):
        return len(self.sourats)

    # Other methods ...

class Sourat(Iterable):

    sourats_titles = [ # 114 strs here
    ]

    def __init__(self, …
Run Code Online (Sandbox Code Playgroud)

python nlp python-3.x

-1
推荐指数
1
解决办法
36
查看次数

标签 统计

nlp ×1

python ×1

python-3.x ×1