Converting a set of data to string and then into a file

Shufen s4046441 at student.uq.edu.au
Thu Oct 7 15:30:58 CEST 2004


Hi,
 
I have set up a upload form where user can add data into the form via
a web browser and submit it. And these data entered by the user will
be grabbed by:

xxxx = data.getvalue.('xxxx')     # data is the name of the form

and converted into a string by using:
str = "<xxxx>" + xxxx + "</xxxx>" + "\n"     # wanna to include the
tags
                                               into the file.

then write them into a file.

I'm trying to combine a bunch of data collected from a upload form
into a string and write it into a file. It works fine if the user
input each and every fields but it showed the following error if the
user did not. And
these fields are not compulsory, they may or may not have values. So
how should I do it? The error stated that I can't concatenate 'str'
and 'NoneType'.
 
Any help is greatly appreciated.
 
Thank you.

Shufen
 
 #####################################################
A problem occurred in a Python script. Here is the
 sequence of function calls leading up to the error,
in the order they occurred.

/var/www/cgi-bin/sf/run_des.py
192         str += "<blame>" + blame + "</blame>" + "\n"
193         str += "<date_string>" + date_string + "</date_string>" +
"\n"
194         str += "<nozzle>" + nozzle + "</nozzle>" + "\n"
195         str += "<shocktube>" + shocktube + "</shocktube>" + "\n"
196         str += "<reservoir>" + reservoir + "</reservoir>" + "\n"
str = '<facility_name>T4 Shock
Tunnel</facility_name>\n<...F/PJ</blame>\n<date_string>05/10/04</date_string>\n',
nozzle = None

TypeError: cannot concatenate 'str' and 'NoneType'
objects
      __doc__ = 'Inappropriate argument type.'
      __getitem__ = <bound method
TypeError.__getitem__ of <exceptions.TypeError
instance at 0x81d31dc>>
      __init__ = <bound method TypeError.__init__ of
<exceptions.TypeError instance at 0x81d31dc>>
      __module__ = 'exceptions'
      __str__ = <bound method TypeError.__str__ of
<exceptions.TypeError instance at 0x81d31dc>>
      args = ("cannot concatenate 'str' and
'NoneType' objects",) 
 
######################################################



More information about the Python-list mailing list