<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span></span></div><div>Well, I'm not answering your question since I am rewriting the script, because I prefer it this way :)<br><br>def addline(line):<br>    return "<tr>%s</tr>\n" % line<br><br>def addcolumn(item,nb_columns):<br>    if nb_columns != 3:<br>        return "<td colspan='%s'>%s</td>" % (3 - nb_columns + 1, item)<br>    return "<td>%s</td>" % item<br><br>output = "<table>\n"<br>for line in file("data.txt"):<br>    items = line.strip().split("\t")<br>    columns = ""<br>    for item in items :<br>        columns += addcolumn(item,len(items))<br>    output  += addline(columns)<br><br><br>output
 += "</table>"<br>print output<br><br><br>printed<br><br>>>> <table><br><tr><td colspan='3'>Price table</td></tr><br><tr><td>1 </td><td> Green apple </td><td> $1</td></tr><br><tr><td>5 </td><td> Green apples </td><td> $4</td></tr><br><tr><td>10 </td><td> Green apples </td><td> $7</td></tr><br></table><br>>>> <br><br><br><br><br>________________________________<br> From: Kurt Hansen <kurt@ugyldig.invalid><br>To: python-list@python.org <br>Sent: Sunday, January 6, 2013 2:38 PM<br>Subject: Re: How to modify this script?<br><br>Den 06/01/13 13.58, chaouche yacine skrev:<br>> if len(columns) != 3:<br>>     colspan = 3 - len(columns) + 1<br>>     output += '<td colspan=%s>' % (colspan) + item +
 '</td> '<br>><br>> I did not test. Use with caution.<br><br>I've tried to put it in several different places in the script, but with <br>no luck; remember that I'm not experienced, so please tell me exactly <br>where it's surposed to be inserted. Could you eventually show the <br>complete modified script?<br><br>><br>> ------------------------------------------------------------------------<br>> *From:* Kurt Hansen <kurt@ugyldig.invalid><br>> *To:* python-list@python.org<br>> *Sent:* Sunday, January 6, 2013 1:42 PM<br>> *Subject:* How to modify this script?<br>><br>> <a target="_blank" href="http://www.tuxradar.com/content/save-time-gedit-snippets">http://www.tuxradar.com/content/save-time-gedit-snippets</a>:<br>><br>> To convert tab-separated text lines into a HTML-table:<br>><br>> $<<br>> lines = $GEDIT_SELECTED_TEXT.split("\n");<br>> output = '<table\>\n';<br>><br>> for line
 in lines:<br>>      output += '<tr\>';<br>><br>>      columns = line.split("\t");<br>>      for item in columns:<br>>          output += '<td\>' + item + '</td\> '<br>><br>>      output += '</tr\>\n';<br>><br>> output += '</table\>';<br>> return output<br>>  ><br>><br>> I would like to make a small modification (I'm not a programmer myself).<br>> Let's say I have these lines:<br>><br>> Price table<br>> 1 <tab> Green apple <tab> $1<br>> 5 <tab> Green apples <tab> $4<br>> 10 <tab> Green apples <tab> $7<br>><br>> Since there's only one "field" in the first line, I want this output:<br>><br>> <tr><td colspan="3">Price table</td></tr><br>><br>> - insted of<br>><br>> <tr><td>Price
 table</td></tr><br>><br>> How to? Thank you i advance.<br>> -- Venlig hilsen<br>> Kurt Hansen<br>> -- <a target="_blank" href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a><br>><br>><br><br><br>-- <br>Venlig hilsen<br>Kurt Hansen<br>-- <br><a target="_blank" href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a></div> </div></body></html>