Peter Otten <__pete...@web.de> wrote: > c...@isbd.net wrote: > > > It's absolutely right, there is a non-UTF character in the column. > > However I don't want to have to clean up the data, it would take > > rather a long time. How can I trap the error and just put a Null or > > zero in the datagrid? > > > > Where do I put the try:/except: ? > > Handle the problem earlier on by setting a text_factory that ignores or > replaces the offending bytes: > > db = sqlite3.connect(...) > db.text_factory = lambda b: b.decode("utf-8", "replace") > > https://docs.python.org/2.7/library/sqlite3.html#sqlite3.Connection.text_factory > https://docs.python.org/2/howto/unicode.html > Brilliant, thank you, works perfectly and (IMHO) is about the neatest possible solution.
-- Chris Green ยท -- https://mail.python.org/mailman/listinfo/python-list