Skip to content

Instantly share code, notes, and snippets.

@physacco
Created May 6, 2013 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save physacco/5523675 to your computer and use it in GitHub Desktop.
Save physacco/5523675 to your computer and use it in GitHub Desktop.
Functions to parse config.py.
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