Python错误:object .__ new __()不带参数

时间:2013-02-26 22:50:20

标签: python api

我收到错误:

object.__new__() takes no parameters

当我运行以下程序时:

import urllib as net
class weather:
    api = "http://www.google/ig/api?weather="
    wData = None
    def _init_(self,location):
        self.api = self.api + location
        self.wData = net.urlopen(self.api).read()
    def showXML(self):
        return self.wData


w = weather("11570")
w.showXML()

2 个答案:

答案 0 :(得分:4)

你有:

def _init_(self,location):

你的意思是?

def __init__(self, location):

特殊方法名称始终以两个下划线开头和结尾。

另外,包含一个回溯并提及您正在使用的Python版本 - 我假设为3,或者您的类默认不会从object继承。

答案 1 :(得分:1)

如果您逐字粘贴代码,则__init__定义中存在错误(通知,每边2 _