给出这个示例类,我想知道BITBUCKET_API_URL
vs self.attribute_name
等自由浮动内容的优缺点。我的同事解释了为什么一次,但他现在不在这里。谢谢
class BitbucketAPIHoss(object):
BITBUCKET_API_URL = 'https://bitbucket.org/api/1.0/'
BITBUCKET_HEADERS = {'Content-Type': 'application/json'}
def __init__(self, username='codyc54321', password='feel_the_already_horrific_economy_bern'):
self.username = username
self.password = password
def get_bitbucket_project_names(self):
repo_dicts = self.get_bitbucket_response_as_dict('user/repositories')
repo_names = extract_values(key='name', dictionaries=repo_dicts)
return repo_names
def create_repository():
pass
def get_bitbucket_response_as_dict(self, url_ending):
url = os.path.join(self.BITBUCKET_API_URL, url_ending)
r = requests.get(url, auth=(self.username, self.password), headers=self.BITBUCKET_HEADERS)
content = r.text
payload = demjson.decode(content)
return payload