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

S

Shufen

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

######################################################
 
T

Thomas Guettler

Am Thu, 07 Oct 2004 06:30:58 -0700 schrieb Shufen:
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
The error stated that I can't concatenate 'str'
and 'NoneType'.

Hi,

You can do it like this:

foo=data.getvalue("....")
if foo==None:
foo=""

Then you can concatenate the values.

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top