[Python-ideas] Rewriting file - pythonic way

Elazar elazarg at gmail.com
Sun Apr 15 06:22:54 EDT 2018


This pitfall sounds like a good reason to have such a function in the
standard library.

Elazar

בתאריך יום א׳, 15 באפר׳ 2018, 13:13, מאת Serhiy Storchaka ‏<
storchaka at gmail.com>:

> 15.04.18 12:49, Alexey Shrub пише:
> > В Воскресенье, 15 апр. 2018 в 12:40 , Serhiy Storchaka
> > <storchaka at gmail.com> написал:
> >> If the problem is that you want to use a single line instead of three
> >> line, you can add a function
> >
> > Yes, I think that single line with word 'rewrite' is much more readable
> > than those three lines.
> > And yes, I can make my own function, but it is typical task - maybe it
> > must be in standard library?
>
> Not every three lines of code must be a function in standard library.
> And these three lines don't look enough common.
>
> Actually the reliable code should write into a separate file and replace
> the original file by the new file only if writing is successful. Or
> backup the old file and restore it if writing is failed. Or do both. And
> handle hard and soft links if necessary. And use file locks if needed to
> prevent race condition when read/write by different processes. Depending
> on the specific of the application you may need different code. Your
> three lines are enough for a one-time script if the risk of a powerful
> blackout or disk space exhaustion is insignificant or if the data is not
> critical.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180415/950707ce/attachment.html>


More information about the Python-ideas mailing list