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

Martin martin at marcher.name
Fri Dec 26 21:42:34 CET 2008


I'd create a simple wrapper object

class MailAddress(object):
  def __init__(self, address=None):
    self.address = address
  def __str__(self):
    if address:
      return self.adress
    return "NULL"

you can keep most of your code just replace the original instantiation
of the mail str-instance with the MailAddress

This is just scratched up quickly. Hope it helps


2008/12/26 Gilles Ganault <nospam at nospam.com>:
>        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.
> --
> http://mail.python.org/mailman/listinfo/python-list


You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html

More information about the Python-list mailing list