Checking each item in m.group()?
nospam at nospam.com
Mon Jun 16 01:48:59 CEST 2008
On Mon, 02 Jun 2008 17:49:11 -0700, Scott David Daniels
<Scott.Daniels at Acm.Org> wrote:
>(c, "NULL") is a tuple; it is being indexed by the boolean "c == ''"
>Since False is 0, and True is 1, the expression picks out "NULL"
>exactly when c is the zero-length string.
Thanks Scott, and also to Peter above, and sorry for not having
I'm having two problems: The first code doesn't strip the
double-quotes when the string is empty. IOW, "not empty" or NULL, but
The second code hits "IndexError: list index out of range" because of
Yield() which I don't seem to be using correctly:
p = re.compile("^(\d+)\t(.*?)")
for line in textlines:
m = p.search(line)
sql = sql + 'INSERT INTO mytable (col1,col2) VALUES
("%s","%s");' % tuple ((c,"NULL")[c == ''] for c in m.groups())
import sqlite3 as sqlite
for row in csv.reader(infile):
#IndexError: list index out of range
#BAD yield row, row or None
#BAD yield row or None, row or None
db = sqlite.connect("test.sqlite")
cursor = db.cursor()
#How to handle empty columns, ie. <TAB><TAB>?
cursor.executemany("insert into mytable (col1,col2) values (?,?);",
if __name__ == "__main__":
More information about the Python-list