Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import inspect
- import json
- from os.path import isfile as exists
- from pprint import pprint
- class TestClass(object):
- config_file = dict()
- def get_my_name(self):
- ans = []
- frame = inspect.currentframe().f_back
- tmp = dict(list(frame.f_globals.items()) + list(frame.f_locals.items()))
- for k, var in tmp.items():
- if isinstance(var, self.__class__):
- if hash(self) == hash(var) and k is not 'self':
- ans.append(k)
- return ans[0]
- def load(self):
- file_name = self.get_my_name()+'.json'
- if exists(file_name):
- with open(file_name) as f:
- self.config_file = json.load(f)
- def save(save):
- file_name = self.get_my_name()+'.json'
- if self.config_file:
- with open(file_name) as f:
- json.dump(self.config_file, f)
- def print_it(self):
- if self.config_file:
- pprint(self.config_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement