Try-except for flow control in reading Sqlite

Victor Hooi victorhooi at gmail.com
Mon Oct 28 02:57:16 EDT 2013


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 at 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




More information about the Python-list mailing list