0
我正在嘗試將該參數傳遞給另一個方法,並且出現異常。將參數傳遞給python webpy中的另一個方法
import web
import json
class Process:
def request(self, query_string):
print query_string
def GET(self):
params = web.input()
request(params)
return json.dumps(dict(foo=55))
這給了我。
<type 'exceptions.NameError'> at /process
global name 'request' is not defined
任何人都可以解釋爲什麼我不能將變量傳遞給另一種方法。
這是否與'請求'方法沒有接收'self'作爲第一個參數有關?實際上,它正在接收'self',但不是按照預期的那樣接收query_string。它不應該是def request(self,query_string)嗎? –
我也嘗試過自我作爲第一個參數 – Kathick
它與自己的第一個參數仍然是一樣的錯誤嗎? 此外,爲什麼該方法定義爲請求,並稱爲do_request? 你試過用self.request(params)來調用它嗎 –