Python Forum
Argparse error when inputting values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Argparse error when inputting values
#2
First, put your code inside python tags so it is easily readable (and so indentation can be seen).

Second, how are you running it? Are you giving an argument to -n? When I do I get a str error instead of a NoneType error.

You haven't told argparse that -n is required, so it will let you run without the argument. Also, the default is to read the argument as a string. So num_nums is a string and the print won't work when you ask it to format a string with %d.

You can modify the add_argument to resolve both. Something like

parser.add_argument("-n", type=int, required=True, help="Number to add")
Reply


Messages In This Thread
Argparse error when inputting values - by tqader - Sep-11-2020, 06:38 PM
RE: Argparse error when inputting values - by bowlofred - Sep-11-2020, 07:08 PM
RE: Argparse error when inputting values - by buran - Sep-11-2020, 07:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug argparse io issue pyDream 8 961 Apr-02-2024, 12:42 PM
Last Post: pyDream
  Trying to use 2 values from excel in my script but getting error.. cubangt 3 1,760 May-11-2022, 07:12 AM
Last Post: normanwolf
  Not able to figure out what is wrong with argparse radioactive9 31 9,303 Mar-16-2022, 07:50 PM
Last Post: deanhystad
  Unable to understand how given code takes a fixed input value, without inputting. jahuja73 4 2,833 Jan-28-2021, 05:22 PM
Last Post: snippsat
  argparse --help in one line. Denial 1 2,075 Sep-20-2020, 03:38 PM
Last Post: deanhystad
  Why this pycharm warning for argparse formatter_class value? pjfarley3 2 2,222 Sep-09-2020, 05:23 AM
Last Post: pjfarley3
  Can argparse support undocumented options? pjfarley3 3 2,369 Aug-14-2020, 06:13 AM
Last Post: pjfarley3
  In ArgParse, can two compatible formatter_class values be used? pjfarley3 2 2,727 Jul-31-2020, 02:01 PM
Last Post: pjfarley3
  Error: too many values to unpack Mike 1 5,197 Oct-30-2019, 03:07 PM
Last Post: buran
  Letters with Accents Not Inputting Phylus 0 1,508 Jun-12-2019, 04:05 PM
Last Post: Phylus

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020