Skip to content

Instantly share code, notes, and snippets.

@benhosmer
Created September 11, 2012 01:14
Show Gist options
  • Save benhosmer/3695255 to your computer and use it in GitHub Desktop.
Save benhosmer/3695255 to your computer and use it in GitHub Desktop.
Read command-line arguments and a configuration file using python.
#!/usr/bin/env python
import ConfigParser
import sys
options = sys.argv
print "Sys Args: ", options[1]
Config = ConfigParser.ConfigParser()
Config.read("config.cfg")
print "Config File Sections: "
print Config.sections()
print Config.options('SectionTwo')
"""
Sample config.cfg file:
[SectionnOne]
Status: Single
Name: Derek
Value: Yes
Age: 29
Single: True
[SectionTwo]
FavoriteColor=Green
[SectionThree]
FamilyName: Johnson
[Others]
Route: 66
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment