[Python-ideas] `to_file()` method for strings
Sven R. Kunze
srkunze at mail.de
Wed Mar 23 18:20:30 EDT 2016
On 23.03.2016 05:35, Thomas Nyberg wrote:
> Not to knock too much on R, but this kind of thing was one of the
> things I always really hated about that language. Separating the
> operations of converting a string and then
> writing/printing/sending/etc. that string is just so much more flexible.
and inconvenient.
I am no social scientist but I share the sentiment.
bash: echo "my string" >> my_file
python: with open('my_file', 'w') as f: f.write('my string')
Hmm. Python actually is best at avoiding special characters but
regarding files, it's still on the level of C.
> It reminds me of the many objects I worked with in R that had natural
> print methods, but did not have natural conversions to strings (at
> least nowhere near as easy as it should have been). There were so many
> times that having the operations as separate steps (e.g. having print
> just call call __str__() or whatever) is so much better.
>
Maybe, I am missed that but when did Nick talk about non-string to be
written to a file?
> I understand the argument that it feels more natural to certain
> people, but it really incentivizes bad design imo.
I disagree. It incentivizes good design as it forces you to prepare 1)
your file name and 2) your data properly and 3) you don't "invent"
self-proclaimed-but-not-really atomic writes.
I can tell you from my experience with several aged Python developers
that they regularly fail to implement atomic file operations. Just saying.
> Definitely a big -1 from me.
+1 from me.
Best,
Sven
More information about the Python-ideas
mailing list