classes and list as parameter, whats wrong?
Hi! I have a problem in a program. And I don't understand what is going on. I can code something, that the "error" doesn't occur anymore. But I still don't know the reason and this is unsatisfactory: Did I understood something wrong or is there a bug? To make it short, I boiled down the program to the crucial part. It looks like this: --- START #!/usr/bin/env python class cClass: """ Base class to handle playlists, i.e. the files, the name, etc. """ def __init__(self, LL=[]): self.list=LL def addFile(self,L): self.list.append(L) def main(): l1 = ['a','b','c'] lNames=['n1','n2','n3'] for name in lNames: objC=cClass() for each in l1: objC.addFile(each) print objC.list del objC if __name__ == "__main__": main() --- END If I start it, I get the following output: ['a', 'b', 'c'] ['a', 'b', 'c', 'a', 'b', 'c'] ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c'] Why does this list grow? I thought, with every new instance the list LL is set to []? How can bring light in this? Best, Dirk -- http://mail.python.org/mailman/listinfo/python-list
Re: classes and list as parameter, whats wrong?
Thanks for your help. * James <[EMAIL PROTECTED]> [2005-08-26 11:42]: > No, the default paramter LL is only ever created once, not > reinitialised every time the constructor is called - this is quite a > common gotcha! But still, it is not absolutely clear for me, what is going on. So, at least just for my understanding: The parameter LL is created just once for the whole class and not for the object (because I del the object explicitly, which should destroy the object)? Thanks, Dirk -- http://mail.python.org/mailman/listinfo/python-list
Re: classes and list as parameter, whats wrong?
Thanks to everyone! I think I understand the things behind this behaviour, now. And as the life goes: Today I found the description of my "problem" in the Python Tutorial! I think I should read it more often, more carefully:-) Best, Dirk -- http://mail.python.org/mailman/listinfo/python-list
How to kill/stop a Thread?
Hi, I like to do the following: Via http I get a stream of data and I like to store this data with a python program. So what I need is to start the downloading and to stop it after a given time. My aproach was to use: urllib.urlretrieve("ULR","FILENAME") It is fine! But how to stop the retrieving? Because it is a constant stream of data there is no natural end. So I thought I use treading.Thread to do it: def retr(): urllib.urlretrieve("URL","FILENAME") t=threading.Thread(target=retr) t.start() It's fine! The data is downloaded and I'm back in my program to do some other stuff. BUT: I cannot stop the download. How can I achieve this? (Another way of solution (w/o threading) would also helpful, of course!) Thanks for your help, Dirk -- http://mail.python.org/mailman/listinfo/python-list