[SQL] Right way to set a variable to NULL?

Gilles Ganault nospam at nospam.com
Fri Dec 26 21:33:32 CET 2008


I use regexes to extract information from a text file. Some of the
records don't have e-mails or www addresses, so those must match Null
in SQL, but None doesn't work as expected:

	if itemmatch:
		web = itemmatch.group(1).strip()
		web = None

	sql = 'INSERT INTO mytable  (name,address,web,mail) VALUES
("%s","%s","%s","%s","%s")' % (name,address,web,mail)

Is there a better way in Python to have a variable match NULL than
building the SQL query step by step?

Thank you.

More information about the Python-list mailing list