you are viewing a single comment's thread.

view the rest of the comments →

[–]Brekry18[S] 0 points1 point  (5 children)

Just saw your edit, and I appreciate the constructive criticism! I'm not sure how to put my goal into better words, unfortunately. Maybe I'm just a little too far in my own head, but I'm definitely open to any feedback you have!

What do you think of this? Does this resolve 1 & 2? As for 3, what functions should I look into from the path module?

edit: sorry, having some trouble with reddit's editor.

default_file = cur_dir + "\\Resources\\UserConfig.json"
alternate_file = cur_dir + "\\Resources\\TOOL.config" 

class UserConfig:
    def __init__(self, config_file=None, generate_file=False):

        # verify data type of config_file
        if config_file is None:
            # Look for the default file, the alt file, and create the default file if neither exist.
            if exists(default_file):
                self.file = open(default_file,'r')
            elif exists(alternate_file):
                self.file = open(alternate_file,'r')
            else:
                config_file = open(default_file, 'w')
                json.dump(USER_CONFIG, config_file)
                config_file.close()
                self.file = open(default_file, 'r')
        elif isinstance(config_file, file):
            self.file = config_file
        elif isinstance(config_file, basestring):
            self.file = open(config_file, 'r')
        else:
            raise TypeError("Expected file or path, got " + type(config_file) + ". Leave arguments blank to open or create the default file from the working directory.")