我学习argparse模块,和我写的代码如下:蟒蛇argparse模块AttributeError的
import argparse
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('integers', metavar='N', type=int, nargs='+',
help='an integer for the accumulator')
parser.add_argument('--sum', dest='accumulate', action='store_const',
const=sum, default=max,
help='sum the integers (default: find the max)')
args = parser.parse_args()
print args.accumulate(args.integers)
我救它作为argparse.py,但是当我在cmd中运行它,它表明:
AttributeError的: '模块' 对象有没有属性 'ArgumentParser'
什么问题谢谢你的帮助
重命名您的argparse.py文件,因为您正在从中导入,您还需要删除任何agparse.pyc文件 –
当您导入时,您正在加载自己,而不是标准库模块。 – cdarke
@PadraicCunningham得到它,非常感谢你 – evbo