Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'model,': 0.05; 'schema': 0.05; 'lookup': 0.09; 'permissions': 0.09; 'try:': 0.09; '(easier': 0.16; 'forgiveness': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'oserror': 0.16; 'sqlite': 0.16; 'subject:flow': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'else,': 0.19; 'file,': 0.19; 'this?': 0.23; 'entries': 0.24; 'errors.': 0.24; 'fine': 0.24; 'mon,': 0.24; 'looks': 0.24; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'quite': 0.32; 'open': 0.33; "i'd": 0.34; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'acceptable': 0.36; 'achieving': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'catch': 0.60; "you're": 0.61; 'victor': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=DWFy79gQ+fr9C01ARp9ZfwddFPOI+HuHsdfsuFoIZXo=; b=zFwJTQSVZKix3ufNdEGCpujZzoGSIsmNXrXhChYXUcKkO6yxBM7bsBLBok4NnMy6ex 5IrX8GG6tQ8atdKsw04dvkGigz5k0JaX5AZtbCrdebRIwHN9ToXNHYZN+lLs67BdqbEk 2Ffu76fVMURGF33kDI7LOqh8sQuB0tIClW+eXLlMKsP4J3AzyTxwxrPjaPznn92uOAzt 0XUw8SQYsMBS8UKlqumn5wYkOjW71l3jG4VOmgYCQOKxAtdLu2k3u8kQ6a80OL2BE5Sm 2SN3y2rf/nlSJ7h87tKQEzsMrcV0kQP+hgr6ns9mtXsyEdMcc3ZpRVI/ovFP/FvU7TBd vMGA== MIME-Version: 1.0 X-Received: by 10.68.170.225 with SMTP id ap1mr14704592pbc.117.1382942165296; Sun, 27 Oct 2013 23:36:05 -0700 (PDT) In-Reply-To: References: Date: Mon, 28 Oct 2013 17:36:05 +1100 Subject: Re: Try-except for flow control in reading Sqlite From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 1382942174 news.xs4all.nl 15915 [2001:888:2000:d::a6]:38937 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:57790 On Mon, Oct 28, 2013 at 2:43 PM, Victor Hooi wrote: > Is it acceptable to use try-except in order to achieve this? E.g.: > > try: > # Try to open up the SQLite file, and lookup the required entries > except OSError: > # Open an empty SQLite file, and create the schema > > > My thinking is that it is (easier to ask forgiveness than permission), but I just wanted to check if there is a better way of achieving this? That looks fine as a model, but is OSError what you want to be catching? I'd go with FileNotFoundError if that's what you're looking for - OSError would also catch quite a bit else, like permissions errors. ChrisA