2015-09-01 30 views
0
def handle_request(param1,param2): 
    if response.error: 
     print "Error:", response.error 
    else: 
     print response.body 
     print param1 
     print param2 


param1 
param2 
http_client = AsyncHTTPClient() 
http_client.fetch("http://www.google.com/", handle_request) 

我需要通过参数1和参数的handle_request下载使用tornado.httpclient - 非阻塞的Python

回答

2

使用functools.partial

import functools 

# handle_response will be called with three arguments: 
# first the ones from the partial, and then the response 
def handle_response(param1, param2, response): pass 

http_client.fetch("http://www.google.com", 
    functools.partial(handle_request, param1, param2)) 
+0

谢谢@Ben达内尔你救我的一天:) –