简体   繁体   English

python wrapper输出是什么意思?

[英]What is the meaning of python wrapper output?

I have written python wrapper for web interface here to print the result of online computation on the terminal. 在这里为Web界面编写了python包装器,以在终端上打印在线计算的结果。 Input to this computation are given through the code. 该计算的输入通过代码给出。 The program I have done is: import re import mechanize import sys import os import urlparse 我做的程序是:导入重新导入机械化导入sys导入os导入urlparse

def calc_relatedness():
    br = mechanize.Browser()
    br.open("http://ws4jdemo.appspot.com/")
    br.select_form(nr = 0)
    br["w1"] = "tree#n#01"
    br["w2"] = "trunk#n#01"
    response = br.submit()
    print response
if __name__ == "__main__":
    calc_relatedness()

and output of above program is: 以上程序的输出为:

<response_seek_wrapper at 0x1ef2878 whose wrapped object = <closeable_response at  0x1efe170 whose fp = <socket._fileobject object at 0x1e8cb50>>>

Can anyone tell me what is the meaning of this output? 谁能告诉我此输出的含义是什么?

Expected output from web computation is: Web计算的预期输出为:

wup( tree#n#1 , trunk#n#1 ) = 0.4762
jcn( tree#n#1 , trunk#n#1 ) = 0.0706
lch( tree#n#1 , trunk#n#1 ) = 1.2040
lin( tree#n#1 , trunk#n#1 ) = 0.1620
res( tree#n#1 , trunk#n#1 ) = 1.3696
path( tree#n#1 , trunk#n#1 ) = 0.0833
lesk( tree#n#1 , trunk#n#1 ) = 1066
hso( tree#n#1 , trunk#n#1 ) = 4 

The output that you see is actually the string representation of the response object, defined in its class. 您看到的输出实际上是response对象的字符串表示形式,在其类中定义。 You see, response actually contains more than the response body itself, it has other information like headers and url, too. 您会看到, response实际上包含的内容比响应主体本身还多,它还具有其他信息,例如标头和url。 Based on this code, if you want to get the response body, you should change the last line in calc_relatedness() to: 基于此代码,如果要获取响应正文,应将calc_relatedness()的最后一行更改为:

print response.read()

You can get some information about response by calling response.info() and response.geturl() . 您可以通过调用response.info()response.geturl()获得有关响应的一些信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM