Python从argparse模块输出AttributeError
Python给出了以下错误:Python从argparse模块输出AttributeError,python,attributes,argparse,attributeerror,Python,Attributes,Argparse,Attributeerror,Python给出了以下错误: Traceback (most recent call last): File "C:\Python34\Google_Map.py", line 246, in <module> main() File "C:\Python34\Google_Map.py", line 232, in main username = args.username AttributeError: 'Namespace' object has no
Traceback (most recent call last):
File "C:\Python34\Google_Map.py", line 246, in <module>
main()
File "C:\Python34\Google_Map.py", line 232, in main
username = args.username
AttributeError: 'Namespace' object has no attribute 'username'enter code here
我建议您检查Python文档中的 它引发
AttributeError
的原因是您使用的属性名称与argparser中使用的参数名称不同
在您共享的错误中,您试图使用username
获取styledbyafrica
参数。这显然行不通。目录也会给你带来问题
def main():
# parse arguments
parser = argparse.ArgumentParser(description='InstaRaider')
parser.add_argument('-styledbyafrica', help='Instagram username')
parser.add_argument('-c:\python34\pikshor images\styledbyafrica', help='Where to save the images')
parser.add_argument('-n', '--num-to-download',
help='Number of posts to download', type=int)
parser.add_argument('-l', '--log-level', help="Log level", default='info')
args = parser.parse_args()
username = args.username
directory = op.expanduser(args.directory)
raider = InstaRaider(username, directory,
num_to_download=args.num_to_download,
log_level=args.log_level)