Skip to content

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

@yashpande

Description

@yashpande

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!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions