AttributeError qsbk 实例没有属性 'stories'

AttributeError qsbk instance has no attribute 'stories'

我的编码如下

首先是我的class设置

class qsbk:
    # standalize some variables
    def __int__(self):
        self.stories = []
        self.pageIndex = 1
        self.user_agent = 'Mozilla/4.0(compatible;MS IE 5.5;Windows NT)'
        #standalize headers
        self.headers = {'User-Agent': self.user_agent}
        self.enable = False

然后激活加载页面

def loadpage(self):
    if self.enable == True:
        if len(self.stories) < 2: 

错误是:

File "C:/Python27/webcapture2.py", line 41, in loadpage if len(self.stories) < 2:

AttributeError: qsbk instance has no attribute 'stories'

构造函数应该是 __init__ 但是你把它命名为 __int__

这可能是原因。看看