2010-10-23 90 views
0
# I have this class: 

class Test(webapp.RequestHandler): 
    myList = [] 
    def get(self): 
     s = [self.request.get('sentence')] 
     self.myList.append(s) 
     htmlcode1 = HTML.table(self.myList) 
     myListLen = len(self.myList) 
     lastItem = self.myList[myListLen-2] 

# I want to add the following to delete the contents of `myList` when I enter 'delete' in the form: 

class Delete(webapp.RequestHandler): 
    def get(self): 
     if s == ['delete']: 
      del self.myList[:] 

如何在Delete()下使用self.myList如何在兩個類中使用相同的變量

回答

6

您可能需要使用

Test.myList 

因爲myList中是類的屬性,而不是這個類的一個特定實例。

相關問題