Created
February 18, 2015 04:27
-
-
Save ashwin/07c417893a3cefaaaeff to your computer and use it in GitHub Desktop.
Read values from INI file using ConfigParser
This file contains 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
#!/usr/bin/env python | |
""" | |
This module provides methods to read values from a INI file. | |
""" | |
import ConfigParser | |
class Config(object): | |
DEFAULT_SEC = "DEFAULT" | |
def __init__(self): | |
self.cparser = None | |
def read_config(self, config_path): | |
self.cparser = ConfigParser.ConfigParser() | |
self.cparser.read(config_path) | |
def get_val(self, key): | |
return self.cparser.get(Config.DEFAULT_SEC, key) | |
def get_str(self, key): | |
return str(self.get_val(key)) | |
def get_int(self, key): | |
return int(self.get_val(key)) | |
def get_float(self, key): | |
return float(self.get_val(key)) | |
def main(): | |
print __doc__ | |
if "__main__" == __name__: | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment