Python Forum
Argparse error when inputting values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Argparse error when inputting values
#1
I'm trying to resolve the errors in this code. We are trying to use argparse, and I get to num_nums = len(args.n) and I get errors. The error gets generated when reading the next line and reads as:

ERROR CODE
Error:
print("Adding %d numbers." % num_nums) TypeError: %d format: a number is required, not NoneType
I can't figure out what is failing with the %d argument that is being passed.
I am looking for assistance with the code to get it to a working state. Full code is:

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-n", help="Number to add")
parser.add_argument("--indent", help="Indent output")

args = parser.parse_args()

num_nums = (args.n)
print("Adding %d numbers." % num_nums)
sum = 0
for n in range(0, num_nums):
    sum = sum + args.n[n]

if (args.i):
    print("\tSum = %d" % sum)
else:
    print("Sum = %d" % sum)
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 buran - Sep-11-2020, 07:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug argparse io issue pyDream 8 805 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,722 May-11-2022, 07:12 AM
Last Post: normanwolf
  Not able to figure out what is wrong with argparse radioactive9 31 8,919 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,781 Jan-28-2021, 05:22 PM
Last Post: snippsat
  argparse --help in one line. Denial 1 2,033 Sep-20-2020, 03:38 PM
Last Post: deanhystad
  Why this pycharm warning for argparse formatter_class value? pjfarley3 2 2,170 Sep-09-2020, 05:23 AM
Last Post: pjfarley3
  Can argparse support undocumented options? pjfarley3 3 2,290 Aug-14-2020, 06:13 AM
Last Post: pjfarley3
  In ArgParse, can two compatible formatter_class values be used? pjfarley3 2 2,657 Jul-31-2020, 02:01 PM
Last Post: pjfarley3
  Error: too many values to unpack Mike 1 5,161 Oct-30-2019, 03:07 PM
Last Post: buran
  Letters with Accents Not Inputting Phylus 0 1,483 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