Tuple to string problems

Alastair G. Hogge agh at tpg.com.au
Thu Aug 14 15:37:09 CEST 2003

Hello *,

I'm using Python and the cgi module to retrive data from a HTML form.
I'm then trying to get that information into a string. But efforts fail when
I run type(foo) on my string. type() returns tuple.

My codes follows:

import cgi
import time
import SeAnRe

# Begin
form = cgi.FieldStorage() # Grab the data from web page form

qu = "("
for name in form.keys():
        qu += "'" + str((form[name].value)) + "'," 

# Now we remove the 'Submit' text added by form key above and replace it
with it with the date, time and a closing ")"
tail = "'" + str(time.strftime("%Y-%m-%d")) + "','" +
str(time.strftime("%H:%M:%S")) + "')"
final_qu = SeAnRe.Action("'Submit',", tail, qu)

So basicly final_qu would be ('1','two','hello','2003-08-14','23:32:07')
However has stated above type(final_qu) return tuple.
I did get a little advice on running str on every element of final_qu like
foo = ""
for k in final_qu.get_each_value:
        foo += str(k)

But then I get "AttributeError: 'tuple' object has no attribute

The reason I need foo to be a string is because I'm using pgdb. A Python
interface to PostgreSQL.

Any would be great.
Thanks in advance

More information about the Python-list mailing list