Skip to content

Instantly share code, notes, and snippets.

@soulston
Created October 20, 2014 16:10
Show Gist options
  • Save soulston/70ca504cff95856d6f77 to your computer and use it in GitHub Desktop.
Save soulston/70ca504cff95856d6f77 to your computer and use it in GitHub Desktop.
Python: using ini files
# See https://wiki.python.org/moin/ConfigParserExamples
import ConfigParser
Config = ConfigParser.ConfigParser()
# [EBS]
# funnelback_volume_id: vol-5d61515f
#
# [example]
# key: value
# Config.read("conf.ini")
# Get the
response = urllib.urlopen("http://169.254.169.254/latest/user-data")
userData = response.read()
Config.read(userData)
def ConfigSectionMap(section):
dict1 = {}
options = Config.options(section)
for option in options:
try:
dict1[option] = Config.get(section, option)
if dict1[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1
print Config.sections()
print ConfigSectionMap("EBS")
VOLUME_ID = ConfigSectionMap("EBS")['funnelback_volume_id']
print "EBS VOLUME_ID: %s." % (VOLUME_ID)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment