Reputation: 955
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"
Upvotes: 14
Views: 32443
Reputation: 3078
If you use argparse
parsed arguments inside another class (somewhere you do self.args = parser.parse_args()
), you might need to explicitly tell your lint parser to ignore Namespace
type checking. As told by @frans at Avoid Pylint warning E1101: 'Instance of .. has no .. member' for class with dynamic attributes
:
Just to provide the answer that works for me now - as [The Compiler][1] suggested you can add a rule for the problematic class in your projects
.pylintrc
:[TYPECHECK] ignored-classes=Namespace
Upvotes: 1
Reputation: 474141
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.
Upvotes: 15