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

Chris Barker - NOAA Federal chris.barker at noaa.gov
Wed Mar 30 00:33:31 EDT 2016


>> 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.

Interesting -- now I'm curious -- how does cPython know that the
reference count of that Thread object needs to be increased So it
won't be deleted? Does the start() method call incref() on itself?

-CHB




>
> Python prefers, in the case of ambiguity, to require explicit directives.
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list