开发者

How to use the same variable in two classes

开发者 https://www.devze.com 2023-01-21 07:11 出处:网络
# I have this class: class Test(webapp.RequestHandler): myList = [] def get(self): s = [self.request.get(\'sentence\')]
# 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.myLi开发者_运维技巧st[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[:]

How can I use self.myList under Delete()?


You would want to use

Test.myList

because myList is an attribute of the class, not a particular instance of that class.

0

精彩评论

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