Splitting lines from a database query

Scott David Daniels scott.daniels at acm.org
Tue Dec 26 17:26:42 EST 2006


Peter Machell wrote:
> I can almost do it this way:
> 
> for x in bar:
>             fname = x[0]
>             if fname == "":
>                 fname == "None"
>             sname = x[1]
>             if sname == "":
>                 sname == "None"
> 
>             print "<FNAME>"+fname+"</FNAME>"+"<SNAME>"+sname+"</SNAME>"

for this:
     for row in bar:
         print "<FNAME>%s</FNAME><SNAME>%s</SNAME>" % (
                 row[0] or 'None', row[1] or 'None')


> Except that I should be using a list and loop to do the null checking, 
> and it still stops when (I think) it hits a blank value:
>     TypeError: cannot concatenate 'str' and 'NoneType' objects
What's the data and program that does that?

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list