At Tuesday 26/12/2006 18:57, Peter Machell wrote:

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>"

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

Perhaps this is what you intended to write:

             if fname == "":
                 fname = "None"

and since None != "", you have to test for it:

if fname is None or fname == "":
    fname = "None"

Note that doing this will deliberately write the text "None" whenever the field is empty, so you will never get <FNAME></FNAME>, instead: <FNAME>None</FNAME>. If you want to get the former, use: if fname is None: fname = ""


--
Gabriel Genellina
Softlab SRL

        

        
                
__________________________________________________ Preguntá. Respondé. Descubrí. Todo lo que querías saber, y lo que ni imaginabas, está en Yahoo! Respuestas (Beta). ¡Probalo ya! http://www.yahoo.com.ar/respuestas
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to