r.pelizzi at virgilio.it
Tue Jul 12 20:29:49 EDT 2005
R. Pelizzi wrote: >Wojtek Dabrowski wrote: > > > >>>I'm using the publisher handler and when i refresh a page that returns >>>some html code (a full page, enclosed in html tags) the output is >>>appended to the page (duplicated, if the python script isn't changed). >>> >>> >>> >>> >>I have had a similiar problem. In my case, the output was generated as a >>list of lines, kind of like: >> >>def handler(req): >> page=bla() >> for line in page.x: >> req.write(line) >> >>class bla: >> x = list() >> def __init__(self): >> self.x.append("HTML lines") >> >>Now x=list didn't generate an empty list, but x sometimes still held the >>output generated last time the page was called. I corrected this by >>adding an x= in the __init__ to get: >> >>class bla: >> x = list() >> def __init__(self): >> x= >> self.x.append("HTML lines") >> >>This cleared x of any garbage that might have been there, and it works >>fine now. >> >>I don't know why x=list() didn't generate an empty list, I just know it >>didn't ;) If there's anybody who can actually explain why this happened, >>I'd be grateful. >> >> >> >> >Strange: you're using a class variable but every instance deletes it. >What's the purpose of such a list anyway? Couldn't you just set self.x >in __init__? Also, since i think mod_python reuses the same interpreter >(python session) for multiple requests (opposed to cgi), it is >predictable that class attributes are shared among requests. My class, >though, has only instance variables. These shouldn't be (and arent') >shared in normal-python scripting. Now, i wonder how using mod_python >messes everything up. > > Ok, forget about the whole thing: the behaviour has been observed in the standard interpreter too, and i found a way to fix it. Looks like i still need to wet my feet with python...