What's wrong with too many arguments?

Asked 2 years ago, Updated 2 years ago, 91 views

if  __name__ == "__main__":

 parser = argparse.ArgumentParser()
 parser.add_argument("fn")
 parser.add_argument("js_pl")
 parser.add_argument("-i", "--iteb")
 args = parser.parse_args()

 if args.iteb:
       _iif(args.js_pl, args.fn)
 else:
      _gwf(args.js_pl, args.fn)

 _glp(args.fn)
  print "end"

Using argparse to obtain a function value and substitute it with a defined function

It says, "too new argumnet.

I don't know where the problem is.

syntax python-2.7

2022-09-22 08:13

1 Answers

The program you wrote requires an input value when it runs. For example, if the file name is a.py,

python a.py aaa bbb At least two values must be passed, as shown in , and you can also give the option -i if you want.

If you run as above, args.js_pl will contain the value bbb, and args.fn will contain the value aaa.

And depending on whether you have the -i option, you're using a function called in the if statement.


2022-09-22 08:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.