我正在编写网络服务器,用一些文件夹中的文件列表回复我:
test_folder = 'somefolder'
class TestLoader(object):
data = []
index = 0
def __init__(self, dir):
for sub in os.listdir(dir):
self.data.append(sub)
class TesterServer(object):
@cherrypy.expose
def index(self):
return "Test server works!"
@cherrypy.expose
def test(self):
tm = helper.TestManager(test_folder)
msg = ''
for i in tm:
msg += "\t %s" % i
return msg
cherrypy.quickstart(TesterServer())
问题是:当我正在重新加载页面时,数据正在被复制,而不是刷新。
即:
页面加载:aaa bsbt bstat bump.py cherry.py helper.py
页面重新加载:aaa bsbt bstat bump.py cherry.py helper.py aaa bsbt bstat bump.py cherry.py helper.py
页面重新加载#2:aaa bsbt bstat bump.py cherry.py helper.py aaa bsbt bstat bump.py cherry.py helper.py aaa bsbt bstat bump.py cherry.py helper.py
诸如此类
我做错了什么? 提前致谢
答案 0 :(得分:1)
您已将data
作为类属性。改为分配__init__()
。
self.data = []