[Tutor] Handling 'None' (null) values when processing sqlite cursorresults

Alan Gauld alan.gauld at btinternet.com
Wed Jul 14 19:34:59 CEST 2010


"Christian Witts" <cwitts at compuscan.co.za> wrote

>> You need a display function that can strip out the nulls as needed.
>> A simple list comprehension or generator expression would work
>> in this case:
>     print ' '.join(str(field) for field in data if field is not 
> 'None')
>
> The problem with that is if you're relying on a set delimiter you 
> are removing elements so you would be better served by doing 
> `str(field) if field != None else '' for field in record`

True, although in this case we do seem to have a fixed condition
since it's the database's representation of null but I originally 
didn't
notice the quotes around None. When I fixed that I should have
changed is to equals..

>     print ' '.join(str(field) for field in data if field != 'None')

But your modification confuses me. can you explain?
What would the print line look like?

Alan G. 




More information about the Tutor mailing list