Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' Parser '''
- parser = argparse.ArgumentParser(description="Describe your app")
- ''' Command line arguments '''
- # settings file example
- parser.add_argument('-c', '--config', metavar='<config file>', type=argparse.FileType('rb'), default='settings.ini', help='INI file')
- # flag example
- parser.add_argument('-v', '--verbose', help='increased output verbosity', action='store_true')
- # value xample
- parser.add_argument('-i', '--interval', help='interval', action=60)
- ''' parse them '''
- args = parser.parse_args()
- ''' get args from config file '''
- config = ConfigParser.SafeConfigParser()
- config.readfp(vars(args)['c'])
- settings = dict(config.items('global'))
- ''' get config settings '''
- settings['user']
- settings['password']
- ''' get command line args '''
- args.vebose
- args.interval
- --------- Example settings.ini ---------
- [global]
- user = user
- password = password
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement