[Python-ideas] `to_file()` method for strings

Chris Angelico rosuav at gmail.com
Tue Mar 29 22:22:05 EDT 2016


On Wed, Mar 30, 2016 at 9:10 AM, Chris Barker <chris.barker at noaa.gov> wrote:
> It's only relevant for other implementations -- cPython already cleans up
> the file object (any object) when it is no longer referenced.
>
> And I do move the thought experiment along -- it was never specific to file
> objects, but rather:
>
> In the case of temporary objects that are never referred to outside a single
> line of code -- delete it right away.

The problem is that there's no way to be sure. For instance, compare
these lines of code:

from threading import Thread

open("marker").write("Ha")
Thread(target=threadfunc).start()

One of them has finished with the object completely. The other most
certainly has not.

Python prefers, in the case of ambiguity, to require explicit directives.

ChrisA


More information about the Python-ideas mailing list