how do i check if a file exists with python?
David C. Ullrich
ullrich at math.okstate.edu
Sun Dec 31 14:10:30 CET 2000
On Sun, 31 Dec 2000 17:39:21 +0200 (IST), Moshe Zadka
<moshez at zadka.site.co.il> wrote:
>On Fri, 29 Dec 2000 14:02:25 GMT, ullrich at math.okstate.edu (David C. Ullrich) wrote:
>> I sometimes make cumulative backups of files containing
>> important stuff. I sort of need to determine that file.001,
>> file.002 and file.003 already exist and file.004 does not
>> before deciding what to name the current backup file.
>That's *really* evil. What if there is another version of your
>process running??? Damn!, just lost that backup file. In that
>case, I'd go for a Maildir-like algorithm, which promises no colisions.
>Actually, in that case, usually what you want is CVS, but that's
>a matter for another day.
Really evil, oh dear.
In the actual program I was referring to there's no problem
with other processes interfering - it's a program running on
one PC with one user. (The one user is me, and I'm not
likely to have two instances of the gradebook open,
and even if I did I'd have to try really hard to get them
to interfere with each other this way - the backup happens
in response to an explicit user request and I don't see how
I could make this request close enough to simultaneously
in both windows to cause a problem.)
But there's a project coming up that's going to involve
people making additions to a data file through a web
page, and collision avoidance is something I've been
wondering about. No doubt the right solution is an
actual database or CVS or something, but I'm too
stubborn to go with something like that except as a
last resort - doing it myself is more educational
(this is a context where losing data would be just
inconvenient, not a huge disaster.) Is it possible
to give a hint how a "Mailder-like" algorithm
promises no collisions?
More information about the Python-list