Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '(at': 0.04; 'exists.': 0.07; 'subject:file': 0.07; 'string': 0.09; 'archiving': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'second.': 0.09; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'targeting': 0.16; 'tempfile': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'seems': 0.21; 'print': 0.22; 'header:User-Agent:1': 0.23; 'tend': 0.24; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; '(which': 0.31; 'unique,': 0.31; 'file': 0.32; 'running': 0.33; 'could': 0.34; 'but': 0.35; 'i.e.': 0.36; 'method': 0.36; 'two': 0.37; 'to:addr :python-list': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; "you're": 0.61; 'name': 0.63; 'happen': 0.63; 'different': 0.65; 'finish': 0.65; 'occur': 0.65; 'received:12': 0.81; 'subject:Save': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Emile van Sebille Subject: Re: Save to a file, but avoid overwriting an existing file Date: Wed, 12 Mar 2014 12:38:54 -0700 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 12.184.110.78 User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394653162 news.xs4all.nl 2956 [2001:888:2000:d::a6]:37019 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68293 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