[Tutor] Zope ZSQL/Python Question
KJZZ Webmaster
kjzz.webmaster at riomail.maricopa.edu
Fri Aug 27 21:47:28 CEST 2004
I am trying to export the results of a zsql method to an excel file
(actually a tab delimited text file) using python.
Everything is working fairly well, except the columns for questions 4 and 5
in the table are of the list data type.
For instance, Question 4 looks like this:
['a', 'b', 'c', 'd']
or
['a', 'd']
depending on which answers a person chose.
In the export, I am looking to have columns and data for Question4a,
Question4b, Question4c, Question4d
and simply have empty tabs in place of an answer if there is no data.
My question is really that most colums in the database have a single value,
however these two columns contain a list.
How might I handle this?
Thanks for any advice you might have.
John Tynan - webmaster
KJZZ.org / KBAQ.or
480.774.8462
-------------- next part --------------
data = context.sqlGetAllSurveys()
container.REQUEST.RESPONSE.setHeader('content-type', 'text/tab-separated-values')
container.REQUEST.RESPONSE.setHeader('Expires','0')
headings = 'Surveyid' + '\t' + 'Listenerid' + '\t' + 'Region' + '\t' + 'Firstname' + '\t' + 'Lastname' + '\t' + 'Updates' + '\t' + 'Question01' + '\t' + 'Question02' + '\t' + 'Question03' + '\t' + 'Question04a' + '\t' + 'Question04b' + '\t' + 'Question04c' + '\t' + 'Question04d' + '\t' + 'Question05a' + '\t' + 'Question05b' + '\t' + 'Question05c' + '\t' + 'Question05d' + '\t' + 'Question05e' + '\t' + 'Question06' + '\t' + 'Question07' + '\t' + 'Question08' + '\t' + 'Question09' + '\t' + 'Question10' + '\t' + 'Question11' + '\t' + 'Completed'
print headings
for i in data:
print i.surveyid, '\t', i.listenerid, '\t', i.region, '\t', i.firstname, '\t', i.lastname, '\t', i.updates, '\t', i.question01, '\t', i.question02, '\t', i.question03, '\t', i.question04, '\t', i.question04, '\t', i.question04, '\t', i.question04, '\t', i.question05, '\t', i.question05, '\t', i.question05, '\t', i.question05, '\t', i.question05, '\t', i.question06, '\t', i.question07, '\t', i.question08, '\t', i.question09, '\t', i.question10, '\t', i.question11, '\t', i.completed, '\r',
return printed
-------------- next part --------------
Surveyid Listenerid Region Firstname Lastname Updates Question01 Question02 Question03 Question04a Question04b Question04c Question04d Question05a Question05b Question05c Question05d Question05e Question06 Question07 Question08 Question09 Question10 Question11 Completed
20040827032207 1204 flagstaff Ireta Keith None, thanks. No Fell in Tub 5 a b a a a b a a a Yes Yes Yes Yes Yes Kereoke Hour. completed
20040827052106 35 phoenix Leora Mossman My name is Lenora. No Some Other Comment. 1 a d a a a f a a a Yes No No No Yes SomeComment completed
More information about the Tutor
mailing list