Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yashpande opened this issue Nov 28, 2018 · 0 comments
Open

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

yashpande opened this issue Nov 28, 2018 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@yashpande
Copy link
Collaborator

yashpande commented Nov 28, 2018

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!

@yashpande yashpande added the enhancement New feature or request label Nov 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants