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

Stephen J. Turnbull stephen at xemacs.org
Thu Mar 24 14:02:33 EDT 2016


Andrew Barnert via Python-ideas writes:

 > I do it all the time in other languages when dealing with smallish
 > files. Python's very nice file-object concept, slant toward
 > iterator-based processing, and amazingly consistent ecosystem means
 > that the same issues don't apply, so I'd rarely do the same
 > thing. But for users migrating to Python from another language, or
 > using Python occasionally while primarily using another language, I
 > can see it being a lot more attractive.

It occurs to me that we already have a perfectly appropriate builtin
for the purpose anyway: print.  Add a filename= keyword argument, and
make use of both file= and filename= in the same call an error.  If
that's not the right answer, I don't see how str.to_file() can
possibly be better.


More information about the Python-ideas mailing list