AttributeError: 'Namespace' object has no attribute

前端 未结 3 3573
[愿得一人]
[愿得一人] 2020-12-31 01:42

I am writing a program that uses urllib2 to download CSV data from an http site. The program works fine when run within Python, however I am also trying to use

相关标签:
3条回答
  • 2020-12-31 02:21

    Long story short.

    Arguments in object returned from parser.parse_args() should be accessed via properties rather than via [] syntax.

    Wrong

    args = parser.parse_args()
    args['method']
    

    Correct

    args = parser.parse_args()
    args.method
    
    0 讨论(0)
  • 2020-12-31 02:36

    I had this problem due to a whitespace before the option sting.

    0 讨论(0)
  • 2020-12-31 02:45

    You're parsing command line arguments into args, which is a Namespace with attributes set to the parsed arguments. But you're passing this entire namespace to downloadData, rather than just the url. This namespace is then passed to urlopen, which doesn't know what to do with it. Instead, call downloadData(args.url).

    0 讨论(0)
提交回复
热议问题