【发布时间】:2013-03-02 03:32:01
【问题描述】:
如何创建初始化代码?
当我把__init__ 构造函数总是告诉我参数是错误的。
另外请举一个例子,也使用__new__和一个使用super()的例子,以及我们为什么要使用或不使用它们。
import webapp2
class MainHandler( webapp2.RequestHandler ):
def __init__( self ):
#initialization code/vars
x = 1
def get( self ):
#code for get here
self.response.write( x+1 )
def post( self ):
#code for post here
self.response.write( x+2 )
app = webapp2.WSGIApplication ( [ ('/', MainHandler) ], debug=True )
【问题讨论】:
-
关于何时在此处使用
__new__和super()还有其他问题,请搜索。 -
对“def”和“self”感到抱歉...是删减/过去的事情...已经更正...