python argparse module AttributeError -


i'm learning argparse module,and write code follows:

import argparse  parser = argparse.argumentparser(description='process integers.') parser.add_argument('integers', metavar='n', type=int, nargs='+',                help='an integer accumulator') parser.add_argument('--sum', dest='accumulate', action='store_const',                const=sum, default=max,                help='sum integers (default: find max)')  args = parser.parse_args() print args.accumulate(args.integers) 

i saved argparse.py,but when run in cmd,it shows:

attributeerror: 'module' object has no attribute 'argumentparser'

what's problem?thank help

when import in python, interpreter runs search find file name. first looks file in current folder , in other paths, such as, /usr/lib/python.

therefore, when you're saying import argparse , naming script argparse.py, python takes file , import is.

to avoid this, change name of file else argparse.py.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -