Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- a 2011-07-06 15:13:22.806839373 -0700
- +++ b 2011-07-06 15:12:42.690701304 -0700
- @@ -1,6 +1,7 @@
- #! /usr/bin/env python
- __doc__ = """
- example of cascading options with ConfigParser and OptionParser
- +from : http://thoughtsbyclayg.blogspot.com/2009/10/python-over-riding-options-with.html
- """
- # imports
- @@ -33,18 +34,17 @@
- # read config objects defaults section into a dictionary
- config_options = config.defaults()
- # config_options is dictionary of strings, over-ride toggle to bool
- - config_options['toggle'] = config.getboolean('DEFAULT', 'toggle')
- + for dest in [option.dest for option in parser.option_list if option.action.lower() in ('store_true', 'store_false')]:
- + if config.has_option('DEFAULT', dest) and not isinstance(config_options[dest], bool):
- + config_options[dest] = config.getboolean('DEFAULT',dest)
- +
- # feed dictionary of defaults into parser object
- parser.set_defaults(**config_options)
- # parse command line options
- (options, args) = parser.parse_args()
- - print "option: %s" % options.option
- - if options.toggle:
- - print "toggle is ON"
- - else:
- - print "toggle is OFF"
- + print parser.values
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement