This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author d0n
Recipients bethard, d0n
Date 2014-06-19.03:49:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1403149794.76.0.705668916508.issue21805@psf.upfronthosting.co.za>
In-reply-to
Content
Hi,

first of all I want to thank you (bethard) for your great work and efforts on developing argparse which is a great tool of versatile use in mostly all of my programs. 
I've faced a specific problem while implementing argparse which I have not been able to fix by the functions supplied through argparse or its functions. And here we are getting to it:

---
Lets assume I have a configuration file which sets the argparser argument of "verbose" to True. Further we assume I would have done that by reading a configuration file into an python-dictionary (maybe via ConfigParser or sth. like that) and passing it to the function "set_defaults" of the class "ArgumentParser" from argparse. 

So far so good - now I have my default set. But now my "verbose" switch still is setting the value for "verbose" to True (or False) regardless of the actual state. So, I do not want to set my value for "verbose" to True and neither I want it to set to False (or None) i want it to be set to the opposite value it has till now


{code}

def opposite(bool):
  if bool is True:
    return False
  elif bool is False:
    return True

from argparse import ArgumentParser
parser = ArgumentParser()
parser.set_defaults(**config_defaults)
parser.add_argument('-V', '--verbose', dest='vrb', action='store_const', const=opposite(config_defaults['verbose']), help='switch on/off verbosity')

{/code}


In that case I would be glad to just set my action to 'store_opposite' (or sth. like that).

I am sorry if I have missed something here or was misguiding somehow.

Best regards,
d0n
History
Date User Action Args
2014-06-19 03:49:54d0nsetrecipients: + d0n, bethard
2014-06-19 03:49:54d0nsetmessageid: <1403149794.76.0.705668916508.issue21805@psf.upfronthosting.co.za>
2014-06-19 03:49:54d0nlinkissue21805 messages
2014-06-19 03:49:53d0ncreate