Created
May 6, 2013 06:44
-
-
Save physacco/5523675 to your computer and use it in GitHub Desktop.
Functions to parse config.py.
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
def parse_config_stream(str_or_file): | |
_myglobals, mylocals = {}, {} | |
exec str_or_file in _myglobals, mylocals | |
return mylocals | |
def parse_config_file(filename): | |
_myglobals, mylocals = {}, {} | |
with open(filename) as f: | |
exec f in _myglobals, mylocals | |
return mylocals | |
print parse_config_stream('a = 123\nb = "foo"\n') | |
print parse_config_file('config.py') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment