Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '(at': 0.04; 'exists.': 0.07; 'subject:file': 0.07; 'string': 0.09; 'second.': 0.09; 'python': 0.11; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'module': 0.19; 'seems': 0.21; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'gives': 0.31; 'unique,': 0.31; 'file': 0.32; 'could': 0.34; 'but': 0.35; 'i.e.': 0.36; 'charset:us-ascii': 0.36; 'two': 0.37; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'happen': 0.63; 'finish': 0.65; 'received:50.22': 0.84; 'subject:Save': 0.91 Date: Wed, 12 Mar 2014 08:33:06 -0500 From: Tim Chase To: python-list@python.org Subject: Re: Save to a file, but avoid overwriting an existing file In-Reply-To: References: X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394631173 news.xs4all.nl 2870 [2001:888:2000:d::a6]:49465 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68279 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