Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57793

Re: Try-except for flow control in reading Sqlite

Newsgroups comp.lang.python
Date 2013-10-27 23:57 -0700
References <ac7cf18f-d4f4-41ef-966d-a35d2d0e39a8@googlegroups.com> <mailman.1677.1382942174.18130.python-list@python.org>
Message-ID <aad94bcd-200f-4c2b-8830-d47ec22eca3d@googlegroups.com> (permalink)
Subject Re: Try-except for flow control in reading Sqlite
From Victor Hooi <victorhooi@gmail.com>

Show all headers | View raw


Hi,

We're on Python 2.6 (RHEL based system...) - I don't believe this exposes FileNotFoundError =(.

Cheers,
Victor

On Monday, 28 October 2013 17:36:05 UTC+11, Chris Angelico  wrote:
> On Mon, Oct 28, 2013 at 2:43 PM, Victor Hooi <victorhooi@gmail.com> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Try-except for flow control in reading Sqlite Victor Hooi <victorhooi@gmail.com> - 2013-10-27 20:43 -0700
  Re: Try-except for flow control in reading Sqlite Steven D'Aprano <steve@pearwood.info> - 2013-10-28 06:18 +0000
    Re: Try-except for flow control in reading Sqlite Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-10-28 10:48 +0100
  Re: Try-except for flow control in reading Sqlite Chris Angelico <rosuav@gmail.com> - 2013-10-28 17:36 +1100
    Re: Try-except for flow control in reading Sqlite Victor Hooi <victorhooi@gmail.com> - 2013-10-27 23:57 -0700
      Re: Try-except for flow control in reading Sqlite Chris Angelico <rosuav@gmail.com> - 2013-10-28 18:01 +1100
        Re: Try-except for flow control in reading Sqlite Steven D'Aprano <steve@pearwood.info> - 2013-10-28 07:19 +0000
      Re: Try-except for flow control in reading Sqlite Chris Angelico <rosuav@gmail.com> - 2013-10-28 18:02 +1100
  Re: Try-except for flow control in reading Sqlite Burak Arslan <burak.arslan@arskom.com.tr> - 2013-10-28 10:17 +0200
  Re: Try-except for flow control in reading Sqlite Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-10-28 19:43 -0400
    Re: Try-except for flow control in reading Sqlite Victor Hooi <victorhooi@gmail.com> - 2013-10-31 16:08 -0700
      Re: Try-except for flow control in reading Sqlite Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-10-31 22:45 -0400

csiph-web