Re: of destructors, open files and garbage collection

2007-05-26 Thread massimo s.
> No, it removes the association between the name 'item' and the object it is > currently bound to. In CPython, removing the last such reference will > cause the object to be gc'ed. In other implementations, actual deletion > may occur later. You probably should close the files directly and arra

Re: of destructors, open files and garbage collection

2007-05-24 Thread Terry Reedy
"massimo s." <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Hi, | | Python 2.4, Kubuntu 6.06. I'm no professional programmer (I am a ph.d. | student in biophysics) but I have a fair knowledge of Python. | | I have a for loop that looks like the following : | | for item in long_list

Re: of destructors, open files and garbage collection

2007-05-24 Thread massimo s.
> Relying on the `__del__()` method isn't a good idea because there are no > really hard guaranties by the language if and when it will be called. Ok, I read the __del__() docs and I understand using it is not a good idea. I can easily add a close_files() method that forces all dangling files to

Re: of destructors, open files and garbage collection

2007-05-24 Thread massimo s.
> It will delete the *name* `item`. It does nothing to the object that was > bound to that name. If the name was the only reference to that object, it > may be garbage collected sooner or later. Read the documentation for the > `__del__()` method for more details and why implementing such a meth

Re: of destructors, open files and garbage collection

2007-05-24 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, massimo s. wrote: > I have a for loop that looks like the following : > > for item in long_list: >foo(item) > > def foo(item): >item.create_blah() #<--this creates item.blah; by doing that it > opens a file and leaves it open until blah.__del__() is called

Re: of destructors, open files and garbage collection

2007-05-24 Thread Paul Moore
On 24 May, 16:40, "massimo s." <[EMAIL PROTECTED]> wrote: > Now, what I thought is that if I call > > del(item) > > it will delete item and also all objects created inside item. Sort of, but it's a bit more subtle. You'll stop the name "item" from referring to your item - if nothing else refers to

of destructors, open files and garbage collection

2007-05-24 Thread massimo s.
Hi, Python 2.4, Kubuntu 6.06. I'm no professional programmer (I am a ph.d. student in biophysics) but I have a fair knowledge of Python. I have a for loop that looks like the following : for item in long_list: foo(item) def foo(item): item.create_blah() #<--this creates item.blah;