-3

My python script is being sent "-E" as an argument string but I am getting the following error

error: argument -emIdentify: expected one argument

When I send it ".E" or "_E" everything is fine, how can I get it to accept "-E"

My code is

import argparse

parser = argparse.ArgumentParser(description='')
parser.add_argument("-emIdentify")
logging.debug( 'processing emIdentify: ' + args.emIdentify + "<br/>" )
P.Ellis
  • 55
  • 2
  • 10
  • In `python script.py -emIdentify -E`, the '-E' is seen as a flag string (like '-emidentify'. Use the `=` form as suggested in the answer to get around that limitation. As a matter of form I'd also define your argument with `--emIdentify` (double -- for longer names). – hpaulj May 31 '18 at 15:57
  • This is a known issue; the `=` solution was provided in https://stackoverflow.com/a/16175115/901925 – hpaulj May 31 '18 at 16:11

1 Answers1

1

You can try

python filename.py -emIdentify=-E
Shivam Singh
  • 1,584
  • 1
  • 10
  • 9
  • I'm getting it from an html form input where the user inputs the string they wish to use and it is passed as a parameter. When the user inputs .E or _E all works fine but I get the error for -E. I think it may be the line parser.add_argument("-emIdentify") is being read as parser.add_argument("--E"). – P.Ellis May 31 '18 at 14:12