|
|
Subscribe / Log in / New account

`to_file()` method for strings

From:  Nick Eubank <nickeubank-Re5JQEeQqe8AvxtiuMwx3w-AT-public.gmane.org>
To:  python-ideas-+ZN9ApsXKcEdnm+yROfE0A-AT-public.gmane.org
Subject:  `to_file()` method for strings
Date:  Wed, 23 Mar 2016 03:06:48 +0000
Message-ID:  <CAFWQgO=6aZwyqan8RUBHgQ7bedePWF7MBdGF9MtT024axm-9zg@mail.gmail.com>

As a social scientists trying to help other social scientists move from
language like R, Stata, and Matlab into Python, one of the behaviors I've
found unnecessarily difficult to explain is the "file.open()/file.close()"
idiom (or, alternatively, context managers). In normal operating systems,
and many high level languages, saving is a one-step operation.

 I understand there are situations where an open file handle is useful, but
it seems a simple `to_file` method on strings (essentially wrapping a
context-manager) would be really nice, as it would save users from learning
this idiom.

Apparently there's something like this in the Path library (
https://docs.python.org/dev/library/pathlib.html#pathlib....) ,
but I suspect most people have no idea about that method (I've been doing
python for years and this has always been a personal frustration, and I've
asked several others for better options and no one had one to offer), and
it seems like it would make much more sense as a string method. If someone
has a string they want to save to disk, I can't imagine anyone looking in
the Path library.

I respect the desire to avoid bloat -- the context manager or open/close
idiom has just felt unnecessarily complicated (dare I say unpythonic?) for
a common task.


Thanks!

Nick
_______________________________________________
Python-ideas mailing list
Python-ideas-+ZN9ApsXKcEdnm+yROfE0A@public.gmane.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


to post comments


Copyright © 2016, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds