[英]Python Error: object.__new__() takes no parameters
I get the error: 我得到错误:
object.__new__() takes no parameters
When I run the following program: 当我运行以下程序时:
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()
You have: 你有:
def _init_(self,location):
Did you mean this? 你是这个意思吗
def __init__(self, location):
Special method names always begin and end with two underscores. 特殊方法名称始终以两个下划线开头和结尾。
Also it would've been nice to include a traceback, and mention the version of Python you're using—I assume 3, or your class wouldn't inherit from object
by default. 另外,最好包括一个追溯,并提及您使用的Python版本-我假设为3,否则默认情况下您的类不会从object
继承。
如果您按原样粘贴代码,则__init__
定义中有错误(注意,每边2个_
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.