New issue 69 by AndrewAlex: Request: Method for prompting for arguments let
out
http://code.google.com/p/argparse/issues/detail?id=69
For programs requiring a large number of arguments I make my them optional
and then do something like the code below. This (or a more integrated
implementation) may be useful for argparse.
args = parser.parse_args()
prompt_for_arg(args.name, "Name: ")
prompt_for_arg(args.company, "Company: ")
prompt_for_arg(args.homedir, "Users Home Directory: ")
def prompt_for_arg(argfield, prompt):
if argfield is not None:
return False
try:
argfield = input(prompt)
if len(argfield) > 0:
return True
except:
pass
print("Aborted")
sys.exit()
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
I was too rough in stripping out the code above, the function above does
not work.
This one should
def prompt_for_arg(arg, field, prompt):
if getattr(arg, field) is not None:
return False
try:
r = input(prompt)
if len(r) > 0:
setattr(arg, field, r)
Comment #2 on issue 69 by steven.bethard: Request: Method for prompting for
arguments let out
http://code.google.com/p/argparse/issues/detail?id=69
Closing as WontFix, mainly because I didn't see any additional community
requests for it. Feel free to open a new issue at bugs.python.org
(argparse's new home) if you know of others asking for similar behavior.