Den 06/01/13 15.01, chaouche yacine wrote:
Well, I'm not answering your question since I am rewriting the script,
because I prefer it this way :)

def addline(line):
     return "<tr>%s</tr>\n" % line
[cut]

I surpose I shall put your code between $< and >?

printed

 >>> <table>
<tr><td colspan='3'>Price table</td></tr>
<tr><td>1 </td><td> Green apple </td><td> $1</td></tr>
<tr><td>5 </td><td> Green apples </td><td> $4</td></tr>
<tr><td>10 </td><td> Green apples </td><td> $7</td></tr>
</table>
 >>>

Aha, so you tested it yourself?

When running this in Gedit on four lines of tab-separated text the output is:

%s</tr>\n" % line

def addcolumn(item,nb_columns):
    if nb_columns != 3:
        return "<td colspan='%s'>%s</td>" % (3 - nb_columns + 1, item)
    return "<td>%s</td>" % item

output = "<table>\n"
for line in file("data.txt"):
    items = line.strip().split("\t")
    columns = ""
    for item in items :
        columns += addcolumn(item,len(items))
    output  += addline(columns)


output += "</table>"
print output
>
--
Venlig hilsen
Kurt Hansen
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to