Created
September 11, 2012 01:14
-
-
Save benhosmer/3695255 to your computer and use it in GitHub Desktop.
Read command-line arguments and a configuration file using python.
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 | |
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