Re: Try-except for flow control in reading Sqlite

2013-10-31 Thread Victor Hooi
Hi, You're right, if the databse doesn't exist, the sqlite3 library will simply create it. Hmm, in that case, what is the Pythonic way to handle this then? If the database is new, then it won't have the table I need, and it will return something like: sqlite3.OperationalError: no such tab

Re: Try-except for flow control in reading Sqlite

2013-10-28 Thread Antoon Pardon
Op 28-10-13 07:18, Steven D'Aprano schreef: > On Sun, 27 Oct 2013 20:43:07 -0700, Victor Hooi wrote: > >> Hi, >> >> I'd like to double-check something regarding using try-except for >> controlling flow. >> >> I have a script that needs to lookup things in a SQLite database. >> >> If the SQLite dat

Re: Try-except for flow control in reading Sqlite

2013-10-28 Thread Burak Arslan
On 10/28/13 05:43, Victor Hooi wrote: > Hi, > > I'd like to double-check something regarding using try-except for controlling > flow. > > I have a script that needs to lookup things in a SQLite database. > > If the SQLite database file doesn't exist, I'd like to create an empty > database, and th

Re: Try-except for flow control in reading Sqlite

2013-10-28 Thread Steven D'Aprano
On Mon, 28 Oct 2013 18:01:49 +1100, Chris Angelico wrote: > On Mon, Oct 28, 2013 at 5:57 PM, Victor Hooi > wrote: >> Hi, >> >> We're on Python 2.6 (RHEL based system...) - I don't believe this >> exposes FileNotFoundError =(. > > Ah! I forgot about 2.x, sorry for the nose. Yep, catching OSError

Re: Try-except for flow control in reading Sqlite

2013-10-28 Thread Chris Angelico
On Mon, Oct 28, 2013 at 5:57 PM, Victor Hooi wrote: > Hi, > > We're on Python 2.6 (RHEL based system...) - I don't believe this exposes > FileNotFoundError =(. Ah! I forgot about 2.x, sorry for the nose. Yep, catching OSError would be the thing to do, then! ChrisA -- https://mail.python.org/ma

Re: Try-except for flow control in reading Sqlite

2013-10-28 Thread Chris Angelico
On Mon, Oct 28, 2013 at 6:01 PM, Chris Angelico wrote: > Ah! I forgot about 2.x, sorry for the nose. Yep, catching OSError > would be the thing to do, then! A "nose", apparently, is what happens when your typing stinks. I meant "noise", of course. :) ChrisA -- https://mail.python.org/mailman/li

Re: Try-except for flow control in reading Sqlite

2013-10-28 Thread Victor Hooi
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 wrote: > > > Is it acceptable to use try-except in order to achi

Re: Try-except for flow control in reading Sqlite

2013-10-27 Thread Chris Angelico
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 > > >

Re: Try-except for flow control in reading Sqlite

2013-10-27 Thread Steven D'Aprano
On Sun, 27 Oct 2013 20:43:07 -0700, Victor Hooi wrote: > Hi, > > I'd like to double-check something regarding using try-except for > controlling flow. > > I have a script that needs to lookup things in a SQLite database. > > If the SQLite database file doesn't exist, I'd like to create an empty

Try-except for flow control in reading Sqlite

2013-10-27 Thread Victor Hooi
Hi, I'd like to double-check something regarding using try-except for controlling flow. I have a script that needs to lookup things in a SQLite database. If the SQLite database file doesn't exist, I'd like to create an empty database, and then setup the schema. Is it acceptable to use try-exc