Save to a file, but avoid overwriting an existing file

Tim Chase python.list at tim.thechases.com
Wed Mar 12 09:33:06 EDT 2014


On 2014-03-12 13:29, 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.

Python offers a "tempfile" module that gives this (and a whole lot
more) to you out of the box.

-tkc









More information about the Python-list mailing list