Created
July 12, 2012 07:50
-
-
Save snanda85/3096523 to your computer and use it in GitHub Desktop.
Reading config from a python module instead of a separate configuation format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # config.py | |
| arg1 = 5 | |
| arg2 = 6 | |
| # utils.py | |
| import config | |
| def read_config(arg, default_value=None): | |
| return getattr(config, arg, default_value) | |
| # myapp.py | |
| from utils import read_config | |
| arg1 = read_config("arg1") | |
| if not arg1: | |
| print "arg1 is mandatory" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment