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

Chris Barker chris.barker at noaa.gov
Mon Mar 28 11:45:33 EDT 2016


On Thu, Mar 24, 2016 at 7:22 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> One of the few downsides of Python's popularity as both a scripting
> language and an app development language is that a lot of tutorials
> are written for the latter, and in app development, relying on the GC
> for external resource cleanup isn't a great habit to get into.


no, it's not. though now that think about it, while I understand that
context managers are great as a universal and flexible way to ,well, mange
context, for file objects themselves:

open('a_file', 'w').write(some_stuff)

Is really nice -- while we don't want to make reference-counting garbage
collection a required part of the language in general, I wonder if it would
be practical to make it part of the spec for SOME objects -- i.e kind of
like you can define a given object to be a context manager, you could
define certain objects to clean up after themselves when they go out of
scope. It would sure be nice is this example ;; it would buy us that simple
syntax, the atomic operation, etc...

I have not thought this through AT ALL, but I wonder if one could avoid
requiring a reference counting system by catching at the parsing stage that
that the object created is never assigned to anything -- and this you know
it's going to go out of scope as soon as that line is finished processing.

In fact, if you have a non-reference counting garbage collection system, it
might be helpful to special case all objects with very short lives, so you
don't pile up a bunch of temporaries, etc that have to be collected
later....

-CHB


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160328/2f6797cd/attachment.html>


More information about the Python-ideas mailing list