-1

関数がコードを読み取る方法を変更して、より簡単に管理された変数を使用してクラスをインポートできるようにしたいと考えています。

編集したいライブラリはすべてインポート済みです。

class http_request(object):

  def __init__(self, website_address, valuedictionary):
   self.website_address = website_address
   self.valuedictionary = valuedictionary

  def get(self):
    return requests.get(website_address, params=valuedictionary)

  def post(self):
    return requests.post(website_address, data=valuedictionary)

def postContext(self):
    return requests.post(website_address, data=valuedictionary).context  
def getContext(self):
    return requests.get(website_address, params=valuedictionary).context

htay = http_request(web_add, payload)

print str(htay.postContext)

私はこれを私の応答として取得しています:「バインドされたメソッド http_request.get of < main .http_request object at 0x8735cec>>」

何か案は?

4

1 に答える 1

1

メソッドを呼び出したいと思います。

print str(htay.postContext())
#                         ^^ Need parenthesis to call a method

もちろん、これglobal website_address not definedにより、メソッド内でインスタンス属性を取得する必要があるため、などに関するエラーが発生する可能性がありselfます。

def postContext(self):
    return requests.post(self.website_address, data=self.valuedictionary).context

また、他の方法でも同様の変更を加える必要があります。

于 2013-02-04T16:07:46.833 に答える