Save to a file, but avoid overwriting an existing file

Emile van Sebille emile at fenx.com
Wed Mar 12 20:38:54 CET 2014


On 3/12/2014 5:29 AM, zoom wrote:

> 2. Alternatively, a unique string could be generated to assure that no
> same file exists. I can see one approach to this is to include date and
> time in the file name. But this seems to me a bit clumsy, and is not
> unique, i.e. it could happen (at least in theory) that two processes
> finish in the same second.

I tend to use this method -- prepending the job name or targeting 
different directories per job precludes duplication.  Unless you're 
running the same job at the same time, in which case tempfile is the way 
to go (which I use for archiving spooled print files which can occur 
simultaneously.)

Emile








More information about the Python-list mailing list