0

given this example class, I am wondering what the advantage/disadvantage of free floating things like BITBUCKET_API_URL vs self.attribute_name. My coworker explained why once but he isn't here right now. Thank you

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
codyc4321
  • 9,014
  • 22
  • 92
  • 165
  • `self.variable` is an instance variable and would be created for every instance vs. above which are class variables, only created once. – AChampion Feb 23 '16 at 03:27
  • so since the the constants don't change, the way I have it is slightly faster to run? Guess I did remember but didn't understand – codyc4321 Feb 23 '16 at 03:29
  • 2
    I wouldn't say it is materially faster, but it is more memory efficient depending on the number of instances you create. – AChampion Feb 23 '16 at 03:53

0 Answers0