olgaliak / active-learning-detect

Active learning + object detection
MIT License
100 stars 33 forks source link

Make config self-contained instead of having a static method #49

Open yashpande opened 5 years ago

yashpande commented 5 years ago

This is definitely a "nice thing to potentially have" instead of an issue but something that might make more "pythonic" sense is to have config be a class defined like this:

class Config():
    def __init__(self, config_file):
        self.config = {}
        with open(config_file) as file_:
            for line in file_:
                line = line.strip()
                if line and line[0] is not "#":
                    var,value = line.split('=', 1)
                    self.config[var.strip()] = value.strip()

    def __getitem__(self, key):
        # Potential error-checking code if key not in self.config
        return self.config[key]

Then you can just do config = Config(config_file) and call config["attr"] to get the value of attr in config. This sounds like a pretty useless change but Mike and I had spent a bit of time thinking about how to do a config file in python so I feel like it would be good to have. Let me know if you have any suggestions!