954,546 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

CGI + Python question

Hi,

I am writing a cgi script for a web database query "results" page and I need to display the results in an html table. My question: 'Is there a way to print out a list of words without the commas and the square brackets?' e.g if this is the list: ['cat', 'dog', 'mouse', 'rat'] is there a way i can get it to print cat, dog, mouse, rat (exactly in the green text format ?

I tried running a loop like this:

for word in list:
print word,

but that breaks up the columns of the table since each list consist of different numbers of elements. If u have any ideas, i'd be glad to know.

Thanks in advance,

ymf

ymf
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 
for word in list:
            print word+",",


or did i just miss what you asked?

Freaky_Chris
Master Poster
702 posts since Apr 2008
Reputation Points: 325
Solved Threads: 118
 

I tried ur method what actually happens is the display on pic1. I need it to look like pic2 but without the commas and square brackets. e.g have just canis_familiaris, dog, domestic dog not the whole ['canis_familiaris', 'dog', 'domestic dog'].

Pic1 is ok, but it breaks up the columns into pieces which is not good enough

Hope my question is clear...

PS. files attached are pic1.jpg and pic2.jpg

Attachments pic1.JPG 24.41KB pic2.JPG 29.59KB
ymf
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

Thats ok, I think i figured out a way to solve it!

I use a string function to store each word and then print out the string itself. I'll post it up just in case anyone's interested

line = "" # the string function that stores each word in the list
for word in mlist:
line = line + word + ", "
print line

ymf
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

Yes indeed that is a good way to solve it. Now i have looked at the pictures i can see what your problem really was. And yes how you have done it is correct

Freaky_Chris
Master Poster
702 posts since Apr 2008
Reputation Points: 325
Solved Threads: 118
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You