Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python从argparse模块输出AttributeError_Python_Attributes_Argparse_Attributeerror - Fatal编程技术网

Python从argparse模块输出AttributeError

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

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 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)