views:

23

answers:

1

hi, people. i'm writing web-server that responds me with a list of files in some folder:

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())

The problem is: when i'm reloading page, the data on are being duplicated, not refreshed.

i.e.:

page load: aaa bsbt bstat bump.py cherry.py helper.py

page reload: aaa bsbt bstat bump.py cherry.py helper.py aaa bsbt bstat bump.py cherry.py helper.py

page reload #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

etcetera

What am i doing wrong? Thanks in advance

+1  A: 

You've made data a class attribute. Assign in __init__() instead.

self.data = []
Ignacio Vazquez-Abrams
so it became kinda static member of a class.thanks, it helped!