scrapy - Python 的回调问题
大家讲道理
大家讲道理 2017-04-18 10:05:24
0
2
270
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
大家讲道理
  1. You can use closures to achieve it. The general idea is as follows:

def out():
    class data:
        count = 0
    def inner(l):
        for i in l:
            data.count += 1
        print data.count
    return inner

f = out()
f([1,2,3])
f([23,34,3,43,4]) 
  1. can be marked with a global variable

巴扎黑

Because the framework processes the returned data, changing it to a closure format seems like a big step. For this requirement, I mainly want to reduce the frequency of calls through count. Now I use another method instead, which is to use the current time as a reference. This is equivalent to a global variable.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template