Save-to-file code not quite working completely

dn PythonList at DancesWithMice.info
Mon Aug 10 20:49:33 EDT 2020


On 10/08/2020 05:23, Dennis Lee Bieber wrote:
> On Sun, 9 Aug 2020 11:50:51 +1200, dn via Python-list
> <python-list at python.org> declaimed the following:
>> To be a logomach, let's talk about "update":-
>> May I advise that a 'good practice' would be to create a new file, and
>> thus be able to (also) maintain the old version as a 'backup'.
>> (also: advantage when debugging/testing logic!)
> 
> 	Per the documentation, this is exactly what the "inplace=True" does! It
> renames the original file, then writes the output under the original name.
> Keeping the backup after processing requires providing an explicit
> "backup=.ext" option, otherwise it uses .bak and deletes the file when
> processing completes.


Apologies for incomplete answer.

I have finally remembered why I (have long) steer-clear of fileinput:
a) criticism from Martijn Pieters 
https://www.zopatista.com/python/2013/11/26/inplace-file-rewriting/
b) I can't recall 'my' last application requiring/desiring a flat-file 
that wasn't JSON or YAML.

The above article is (2013) old. I notice that whilst the github 
received a trivial update one month back, that the PyPI entry is almost 
two years old.

I (am biased, admittedly) still maintain that for anything more than the 
trivial, a direct-access mechanism is the tool-for-the-job, and because 
I think they are 'easy', an RDBMS. YMMV!
-- 
Regards =dn


More information about the Python-list mailing list