How to Solve args = parser.parse_args() error

args = parser.parse_args() error


Problem description

args = parser.parse_args() reports an error

import argparse

parser = argparse.ArgumentParser(prog='top', description='Show top lines from each file')
parser.add_argument('filenames', nargs='+')
parser.add_argument('-l', '--lines', type=int, default=10)
# args = parser.parse_args()
args, unknown = parser.parse_known_args() # Modified
print(args)

Solution:
Modify to args, unknown = parser.parse_known_args()

Read More: