Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.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.044 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.01; 'stops': 0.07; 'subject:code': 0.07; 'subject:file': 0.07; 'input,': 0.09; "subject:, '": 0.09; 'received:172.18.0': 0.16; 'subject: \n ': 0.16; 'to:name:python-list@python.org': 0.22; 'header:In-Reply- To:1': 0.27; 'wondering': 0.29; "i'm": 0.30; 'file': 0.32; 'checking': 0.33; 'subject:the': 0.34; 'subject:with': 0.35; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'skip:o 20': 0.38; 'subject:new': 0.38; 'conditions.': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'received:unknown': 0.61; 'subject:Using': 0.84; 'opens': 0.91; 'race': 0.95 X-Cloudmark-SP-Filtered: true X-Cloudmark-SP-Result: v=1.1 cv=/24PZDiXryEUsaYH72AX4ulVzqSXihAXfE7Ql5lDP0I= c=1 sm=1 a=AgG5ixNBvo4A:10 a=XJDAhjgDJnYA:10 a=7PYXob_7ZXMA:10 a=BLceEmwcHowA:10 a=kj9zAlcOel0A:10 a=xqWC_Br6kY4A:10 a=oNw28mxuUhXRB3mVwYQ4Ag==:17 a=u8e7-jQaOBxZnvlltpUA:9 a=CjuIK1q_8ugA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 From: "Joseph L. Casale" To: "python-list@python.org" Subject: RE: Using "with open(filename, 'ab'):" and calling code only if the file is new? Thread-Topic: Using "with open(filename, 'ab'):" and calling code only if the file is new? Thread-Index: AQHO1Q0NHudcB+MlkkSnceEwY5yRgpoMeBnw Date: Wed, 30 Oct 2013 01:42:50 +0000 References: <68bd6cb6-44b2-446c-b0e2-043e3ac1c35b@googlegroups.com> In-Reply-To: <68bd6cb6-44b2-446c-b0e2-043e3ac1c35b@googlegroups.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.18.0.201] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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: 1383097380 news.xs4all.nl 15884 [2001:888:2000:d::a6]:56719 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:57990 > with open(self.full_path, 'r') as input, open(self.output_csv, 'ab') = as > output: > fieldnames =3D (...) > csv_writer =3D DictWriter(output, filednames) > # Call csv_writer.writeheader() if file is new. > csv_writer.writerows(my_dict) >=20 > I'm wondering what's the best way of calling writeheader() only if the fi= le is > new? >=20 > My understanding is that I don't want to use os.path.exist(), since that = opens > me up to race conditions. What stops you from checking before and setting a flag?