开发者

Google App Engine python - Self is not defined

开发者 https://www.devze.com 2022-12-30 17:42 出处:网络
I have a request that maps to this class ChatMsg It takes in 3 get variables, username, roomname, and msg. But it fails on this last line here.

I have a request that maps to this class ChatMsg It takes in 3 get variables, username, roomname, and msg. But it fails on this last line here.

class ChatMsg(webapp.RequestHandler): # this is line 239
    def get(self):
        username = urllib.unquote(self.request.get('username'))
        roomname = urllib.unquote(self.request.get('roomname')) # this is line 242

When it tries to assign roomname, it tells me:

<type 'exceptions.NameError'>: name 'self' is not defined
Traceback (most recent call last):
  File "/base/data/home/apps/chatboxes/1.341998073649951735/c开发者_如何学Pythonhatroom.py", line 239, in <module>
    class ChatMsg(webapp.RequestHandler):
  File "/base/data/home/apps/chatboxes/1.341998073649951735/chatroom.py", line 242, in ChatMsg
    roomname = urllib.unquote(self.request.get('roomname'))

what the hell is going on to make self not defined


This should be an indentation problem. The traceback shows that the error is not in the get() method. You get the NameError exception at the time of the definition of your class. Try to execute the following code, you will get the same exception as you've got.

class ChatMsg(object): # this is line 239
    def get(self):
        username = urllib.unquote(self.request.get('username'))
    roomname = urllib.unquote(self.request.get('roomname')) # this is line 242
0

精彩评论

暂无评论...
验证码 换一张
取 消