Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't solve Python argparse error 'object has no attribute'

When I run this code I get

AttributeError: 'ArgumentParser' object has no attribute 'max_seed'

Here's the code

import argparse
import ConfigParser

CFG_FILE='/my.cfg'

# Get command line arguments
args = argparse.ArgumentParser()
args.add_argument('verb', choices=['new'])
args.add_argument('--max_seed', type=int, default=1000)
args.add_argument('--cmdline')
args.parse_args()

if args.max_seed:
    pass

if args.cmdline:
    pass

My source file is called "fuzz.py"

like image 629
bluedog Avatar asked Mar 17 '14 01:03

bluedog


1 Answers

You should first initialize the parser and arguments and only then get the actual arguments from parse_args() (see example from the docs):

import argparse
import ConfigParser

CFG_FILE='/my.cfg'

# Get command line arguments
parser = argparse.ArgumentParser()
parser.add_argument('verb', choices=['new'])
parser.add_argument('--max_seed', type=int, default=1000)
parser.add_argument('--cmdline')

args = parser.parse_args()
if args.max_seed:
    pass

if args.cmdline:
    pass

Hope that helps.

like image 51
alecxe Avatar answered Sep 17 '22 18:09

alecxe