请问在类里怎么调用类的函数,我想把canshu里返回的数据在order里打印出来,比如我这么写
class DailishiyanDownloaderMiddleware(object):
Not all methods need to be defined. If a method is not defined,
scrapy acts as if the downloader middleware does not modify the
passed objects.
def canshu(self):#数据库返回数据在这个函数
aa=["192.168.1.2","11.22.33","44,55,66"]
return aa
b=canshu(1)
print("我在函数外",b)
def order(self):#将返回数据按顺序输出
print("我来自order")
for i in range(10):
yield i
a=order(1)
@classmethod
def from_crawler(cls, crawler):
# This method is used by Scrapy to create your spiders.
s = cls()
crawler.signals.connect(s.spider_opened, signal=signals.spider_opened)
return s
........
就能正常输出,但我如果这么写,就会报错AttributeError: 'int' object has no attribute 'canshu'
class DailishiyanDownloaderMiddleware(object):
Not all methods need to be defined. If a method is not defined,
scrapy acts as if the downloader middleware does not modify the
passed objects.
def canshu(self):#数据库返回数据在这个函数
aa=["192.168.1.2","11.22.33","44,55,66"]
return aa
b=canshu(1)
#print("我在函数外",b)
def order(self):#将返回数控按顺序输出Ss
print("我来自order",self.canshu())
for i in range(10):
yield i
a=order(1)
@classmethod
def from_crawler(cls, crawler):
# This method is used by Scrapy to create your spiders.
s = cls()
crawler.signals.connect(s.spider_opened, signal=signals.spider_opened)
return s
......
省略的部分是scrapy框架的默认代码,基本没有更改
毫无头绪的bug,求帮助,感谢