ben basitleştirmek için _http()
yöntemi kullanıyorum gördüğünüz gibi buEn iyi uygulama kullanırken httplib2.Http() nesnesi
import httplib2
import urllib
class apiWrapper:
def __init__(self):
self.http = httplib2.Http()
def _http(self, url, method, dict):
'''
Im using this wrapper arround the http object
all the time inside the class
'''
params = urllib.urlencode(dict)
response, content = self.http.request(url,params,method)
gibi bir sınıf ile pythonic web API sarıcı yazıyorum httplib2.Http()
nesnesiyle etkileşim. Bu yöntem sınıf içinde oldukça sık olarak adlandırılır ve bu nesne ile etkileşim için en iyi yolu nedir merak ediyorum: __init__
ve sonra yeniden o _http()
yöntemi denir (olarak
- yılında nesne oluşturmak yukarıdaki kodu)
- içinde gösterilen veya aşağıdaki kod örneğinde gösterildiği gibi
_http()
yöntemi (her çağrı için yöntem içinde httplib2.Http()
nesne oluşturmak Eğer bağlantıları yeniden eğer
import httplib2
import urllib
class apiWrapper:
def __init__(self):
def _http(self, url, method, dict):
'''Im using this wrapper arround the http object
all the time inside the class'''
http = httplib2.Http()
params = urllib.urlencode(dict)
response, content = http.request(url,params,method)