Skip to content

Instantly share code, notes, and snippets.

@arthuralvim
Created May 30, 2017 15:08
Show Gist options
  • Save arthuralvim/48db37817da64e63bd520bca1e82aa97 to your computer and use it in GitHub Desktop.
Save arthuralvim/48db37817da64e63bd520bca1e82aa97 to your computer and use it in GitHub Desktop.
Config Loader
# AWS Lambda Coding & Config (part 4)
# Ben Emson
# https://www.youtube.com/watch?v=o-8U_3s_zWI
import os
import json
class ConfigLoader(object):
CONFIG_FILE = 'config.json'
def config(self):
""" Parse configuration. """
config_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
self.CONFIG_FILE)
if not hasattr(self, '_parsed_config'):
self._parsed_config = self.load(config_file)
return self._parsed_config
def load(self, config_file):
""" Read JSON file and assign it to an instance variable. """
with open(config_file) as data_file:
self._parsed_config = json.load(data_file)
return self._parsed_config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment