类自身属性和内联类变量之间的区别

时间:2016-02-23 03:24:32

标签: python class python-3.x

给出这个示例类,我想知道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

0 个答案:

没有答案