How to modify this script?

Discussion in 'Python' started by Kurt Hansen, Jan 6, 2013.

  1. Kurt Hansen

    Kurt Hansen Guest

    http://www.tuxradar.com/content/save-time-gedit-snippets:

    To convert tab-separated text lines into a HTML-table:

    $<
    lines = $GEDIT_SELECTED_TEXT.split("\n");
    output = '<table\>\n';

    for line in lines:
    output += '<tr\>';

    columns = line.split("\t");
    for item in columns:
    output += '<td\>' + item + '</td\> '

    output += '</tr\>\n';

    output += '</table\>';
    return output
    >


    I would like to make a small modification (I'm not a programmer myself).
    Let's say I have these lines:

    Price table
    1 <tab> Green apple <tab> $1
    5 <tab> Green apples <tab> $4
    10 <tab> Green apples <tab> $7

    Since there's only one "field" in the first line, I want this output:

    <tr><td colspan="3">Price table</td></tr>

    - insted of

    <tr><td>Price table</td></tr>

    How to? Thank you i advance.
    --
    Venlig hilsen
    Kurt Hansen
    Kurt Hansen, Jan 6, 2013
    #1
    1. Advertising

  2. On Sun, Jan 6, 2013 at 11:42 PM, Kurt Hansen <> wrote:
    > Since there's only one "field" in the first line, I want this output:
    >
    > <tr><td colspan="3">Price table</td></tr>
    >
    > - insted of
    >
    > <tr><td>Price table</td></tr>
    >
    > How to? Thank you i advance.


    It's actually quite simple, as long as you don't mind the junk of
    colspan="1" on all the other cells. Just replace the innermost loop
    with:

    for item in columns:
    output += '<td colspan="' + (4-len(columns)) + '"\>' +
    item + '</td\> '

    Untested, but it ought to work - as long as you never have _more_
    cells in the line.

    ChrisA
    Chris Angelico, Jan 6, 2013
    #2
    1. Advertising

  3. Kurt Hansen

    Kurt Hansen Guest

    Den 06/01/13 13.52, Chris Angelico skrev:
    > On Sun, Jan 6, 2013 at 11:42 PM, Kurt Hansen <> wrote:
    >> Since there's only one "field" in the first line, I want this output:
    >>
    >> <tr><td colspan="3">Price table</td></tr>
    >>
    >> - insted of
    >>
    >> <tr><td>Price table</td></tr>
    >>
    >> How to? Thank you i advance.


    > It's actually quite simple, as long as you don't mind the junk of
    > colspan="1" on all the other cells.


    I do, but I would like to test anyway ;-)

    Just replace the innermost loop
    > with:
    >
    > for item in columns:
    > output += '<td colspan="' + (4-len(columns)) + '"\>' +
    > item + '</td\> '


    "innermost"? I have replaced this with yours, but all the marked text
    are deleted:

    for item in columns:
    output += '<td\>' + item + '</td\> '

    > Untested, but it ought to work - as long as you never have _more_
    > cells in the line.

    --
    Regards
    Kurt Hansen
    Kurt Hansen, Jan 6, 2013
    #3
  4. Kurt Hansen

    Kurt Hansen Guest

    Den 06/01/13 13.58, chaouche yacine skrev:
    > if len(columns) != 3:
    > colspan = 3 - len(columns) + 1
    > output += '<td colspan=%s>' % (colspan) + item + '</td> '
    >
    > I did not test. Use with caution.


    I've tried to put it in several different places in the script, but with
    no luck; remember that I'm not experienced, so please tell me exactly
    where it's surposed to be inserted. Could you eventually show the
    complete modified script?

    >
    > ------------------------------------------------------------------------
    > *From:* Kurt Hansen <>
    > *To:*
    > *Sent:* Sunday, January 6, 2013 1:42 PM
    > *Subject:* How to modify this script?
    >
    > http://www.tuxradar.com/content/save-time-gedit-snippets:
    >
    > To convert tab-separated text lines into a HTML-table:
    >
    > $<
    > lines = $GEDIT_SELECTED_TEXT.split("\n");
    > output = '<table\>\n';
    >
    > for line in lines:
    > output += '<tr\>';
    >
    > columns = line.split("\t");
    > for item in columns:
    > output += '<td\>' + item + '</td\> '
    >
    > output += '</tr\>\n';
    >
    > output += '</table\>';
    > return output
    > >

    >
    > I would like to make a small modification (I'm not a programmer myself).
    > Let's say I have these lines:
    >
    > Price table
    > 1 <tab> Green apple <tab> $1
    > 5 <tab> Green apples <tab> $4
    > 10 <tab> Green apples <tab> $7
    >
    > Since there's only one "field" in the first line, I want this output:
    >
    > <tr><td colspan="3">Price table</td></tr>
    >
    > - insted of
    >
    > <tr><td>Price table</td></tr>
    >
    > How to? Thank you i advance.
    > -- Venlig hilsen
    > Kurt Hansen
    > -- http://mail.python.org/mailman/listinfo/python-list
    >
    >



    --
    Venlig hilsen
    Kurt Hansen
    Kurt Hansen, Jan 6, 2013
    #4
  5. On Mon, Jan 7, 2013 at 12:34 AM, Kurt Hansen <> wrote:
    > "innermost"? I have replaced this with yours, but all the marked text are
    > deleted:


    Here's the full code, with my change:

    $<
    lines = $GEDIT_SELECTED_TEXT.split("\n");
    output = '<table\>\n';

    for line in lines:
    output += '<tr\>';

    columns = line.split("\t");
    for item in columns:
    output += '<td colspan="' + (4-len(columns)) + '"\>' +
    item + '</td\> '

    output += '</tr\>\n';

    output += '</table\>';
    return output
    >


    It's only one line of code that needs to be changed. Python loops (and
    other control structures) are defined by indentation, so the innermost
    loop is the one that starts furthest to the right.

    Chris Angelico
    Chris Angelico, Jan 6, 2013
    #5
  6. Kurt Hansen

    Kurt Hansen Guest

    Den 06/01/13 14.44, Chris Angelico wrote:
    > On Mon, Jan 7, 2013 at 12:34 AM, Kurt Hansen <> wrote:
    >> "innermost"? I have replaced this with yours, but all the marked text are
    >> deleted:

    >
    > Here's the full code, with my change:
    >
    > $<
    > lines = $GEDIT_SELECTED_TEXT.split("\n");
    > output = '<table\>\n';


    I'm sorry to bother you, Chris, but applying the snippet with your code
    in Gedit still just deletes the marked, tab-separated text in the editor.
    --
    Venlig hilsen
    Kurt Hansen
    Kurt Hansen, Jan 6, 2013
    #6
  7. On Mon, Jan 7, 2013 at 1:03 AM, Kurt Hansen <> wrote:
    > I'm sorry to bother you, Chris, but applying the snippet with your code in
    > Gedit still just deletes the marked, tab-separated text in the editor.


    Ah, whoops. That would be because I had a bug in the code (that's why
    I commented that it was untested). Sorry about that! Here's a fixed
    version:

    $<
    lines = $GEDIT_SELECTED_TEXT.split("\n");
    output = '<table\>\n';

    for line in lines:
    output += '<tr\>';

    columns = line.split("\t");
    for item in columns:
    output += '<td colspan="' + str(4-len(columns)) +
    '"\>' + item + '</td\> '

    output += '</tr\>\n';

    output += '</table\>';
    return output
    >



    Note that it's a single line:

    output += '<td colspan="' + str(4-len(columns)) + '"\>' + item + '</td\> '

    If your newsreader (or my poster) wraps it, you'll need to unwrap that
    line, otherwise you'll get an IndentError.

    That version should work.

    ChrisA
    Chris Angelico, Jan 6, 2013
    #7
  8. Kurt Hansen

    Kurt Hansen Guest

    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
    Kurt Hansen, Jan 6, 2013
    #8
  9. Kurt Hansen

    Subimal Deb Guest

    Kurt,
    Try this:


    $<
    lines = $GEDIT_SELECTED_TEXT.split("\n");
    output = '<table\>\n';

    for line in lines:
    output += '<tr\>';

    columns = line.split("\t");
    if len(columns)==1:
    output += '<tr\><td colspan="3"\>', line, '</td\></tr\>'
    else:
    for item in columns:
    output += '<td\>' + item + '</td\> '

    output += '</tr\>\n';

    output += '</table\>';
    return output
    >


    ----------------
    All I have done is to
    If there is one item in the tab-separated line :
    print the line as a row spanning 3 columns
    else:
    print the items in the line as an item in each column
    ----------------
    I have not tried this snippet in Gedit - so use with caution.
    ----------------
    good luck,
    Subimal Deb




    On Sunday, January 6, 2013 6:12:11 PM UTC+5:30, Kurt Hansen wrote:
    > http://www.tuxradar.com/content/save-time-gedit-snippets:
    >
    >
    >
    > To convert tab-separated text lines into a HTML-table:
    >
    >
    >
    > $<
    >
    > lines = $GEDIT_SELECTED_TEXT.split("\n");
    >
    > output = '<table\>\n';
    >
    >
    >
    > for line in lines:
    >
    > output += '<tr\>';
    >
    >
    >
    > columns = line.split("\t");
    >
    > for item in columns:
    >
    > output += '<td\>' + item + '</td\> '
    >
    >
    >
    > output += '</tr\>\n';
    >
    >
    >
    > output += '</table\>';
    >
    > return output
    >
    > >

    >
    >
    >
    > I would like to make a small modification (I'm not a programmer myself).
    >
    > Let's say I have these lines:
    >
    >
    >
    > Price table
    >
    > 1 <tab> Green apple <tab> $1
    >
    > 5 <tab> Green apples <tab> $4
    >
    > 10 <tab> Green apples <tab> $7
    >
    >
    >
    > Since there's only one "field" in the first line, I want this output:
    >
    >
    >
    > <tr><td colspan="3">Price table</td></tr>
    >
    >
    >
    > - insted of
    >
    >
    >
    > <tr><td>Price table</td></tr>
    >
    >
    >
    > How to? Thank you i advance.
    >
    > --
    >
    > Venlig hilsen
    >
    > Kurt Hansen
    Subimal Deb, Jan 6, 2013
    #9
  10. Kurt Hansen

    Kurt Hansen Guest

    Den 06/01/13 15.20, Chris Angelico wrote:
    > On Mon, Jan 7, 2013 at 1:03 AM, Kurt Hansen <> wrote:
    >> I'm sorry to bother you, Chris, but applying the snippet with your code in
    >> Gedit still just deletes the marked, tab-separated text in the editor.


    > Ah, whoops. That would be because I had a bug in the code (that's why
    > I commented that it was untested). Sorry about that! Here's a fixed
    > version:
    >

    [cut]>
    > Note that it's a single line:
    >
    > output += '<td colspan="' + str(4-len(columns)) + '"\>' + item + '</td\> '
    >
    > If your newsreader (or my poster) wraps it, you'll need to unwrap that
    > line, otherwise you'll get an IndentError.


    Ahhh, I did'nt realize that. Now it works :)

    > That version should work.


    It certainly does. I'll keep it and use it until at better solution is
    found. In the meantime I can just remove any unnecessary "colspan="1"
    with a macro.

    Thanks for your help.
    --
    Venlig hilsen
    Kurt Hansen
    Kurt Hansen, Jan 6, 2013
    #10
  11. Kurt Hansen

    Kurt Hansen Guest

    Den 06/01/13 15.22, Subimal Deb wrote:
    > Kurt,
    > Try this:
    >

    [cut]

    I've tested it on my original example:

    Price table
    1 Green apple $1
    5 Green apples $4
    10 Green apples $7

    With all four lines selected it makes an error. With only three (without
    the first line) it works all right.

    The error message says:

    Execution of the Python command (lines = 'Price table\n1\tGreen
    apple\t$1\n5\tGreen apples\t$4\n10\tGreen apples\t$7'.split("\n");
    output = '<table>\n';

    for line in lines:
    output += '<tr>';

    columns = line.split("\t");
    if len(columns)==1:
    output += '<tr><td colspan="3">', line, '</td></tr>'
    else:
    for item in columns:
    output += '<td>' + item + '</td> '

    output += '</tr>\n';

    output += '</table>';
    return output) failed: cannot concatenate 'str' and 'tuple' objects
    --
    Venlig hilsen
    Kurt Hansen
    Kurt Hansen, Jan 6, 2013
    #11
  12. On Mon, Jan 7, 2013 at 1:30 AM, Kurt Hansen <> wrote:
    > Den 06/01/13 15.20, Chris Angelico wrote:
    >
    >> On Mon, Jan 7, 2013 at 1:03 AM, Kurt Hansen <> wrote:
    >>>
    >>> I'm sorry to bother you, Chris, but applying the snippet with your code
    >>> in
    >>> Gedit still just deletes the marked, tab-separated text in the editor.

    >
    >
    >> Ah, whoops. That would be because I had a bug in the code (that's why
    >> I commented that it was untested). Sorry about that! Here's a fixed
    >> version:
    >>

    > [cut]>
    >
    >> Note that it's a single line:
    >>
    >> output += '<td colspan="' + str(4-len(columns)) + '"\>' + item + '</td\> '
    >>
    >> If your newsreader (or my poster) wraps it, you'll need to unwrap that
    >> line, otherwise you'll get an IndentError.

    >
    >
    > Ahhh, I did'nt realize that. Now it works :)
    >
    >> That version should work.

    >
    >
    > It certainly does. I'll keep it and use it until at better solution is
    > found. In the meantime I can just remove any unnecessary "colspan="1" with a
    > macro.
    >
    > Thanks for your help.


    Excellent! You'll find that Subimal's solution doesn't have those
    colspan="1" lines, so take your pick as to which way you want to go.

    ChrisA
    Chris Angelico, Jan 6, 2013
    #12
  13. On Mon, Jan 7, 2013 at 1:40 AM, Kurt Hansen <> wrote:
    > failed: cannot concatenate 'str' and 'tuple' objects


    The problem is this line:

    output += '<tr><td colspan="3">', line, '</td></tr>'

    Change it to:

    output += '<tr><td colspan="3">' + line + '</td></tr>'

    ChrisA
    Chris Angelico, Jan 6, 2013
    #13
  14. Kurt Hansen

    Kurt Hansen Guest

    Den 06/01/13 15.52, Chris Angelico skrev:
    > On Mon, Jan 7, 2013 at 1:40 AM, Kurt Hansen <> wrote:
    >> failed: cannot concatenate 'str' and 'tuple' objects

    >
    > The problem is this line:
    >
    > output += '<tr><td colspan="3">', line, '</td></tr>'
    >
    > Change it to:
    >
    > output += '<tr><td colspan="3">' + line + '</td></tr>'


    :)

    Something happened allright, but ...
    Output with this change:

    <td colspan="3">' + line + '</td></tr>'
    else:
    for item in columns:
    output += '<td\>' + item + '</td\> '

    output += '</tr\>\n';

    output += '</table\>';
    return output
    >

    --
    Venlig hilsen
    Kurt Hansen
    Kurt Hansen, Jan 6, 2013
    #14
  15. I'm not confident this would run on gedit. It works on a python interpreterif you have a file named data.txt in the same directory containing your sample data.

    It surely has to do with how gedit works then, because the "$" sign isn't used in python, this business should be a gedit convention. And sorry, I can't help on that, I'm not a user of gedit myself. Fortunately others have answered and I beleive one of the solutions worked for you.



    ________________________________
    From: Kurt Hansen <>
    To:
    Sent: Sunday, January 6, 20133:21 PM
    Subject: Re: How to modify this script?

    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 initems :
            columns += addcolumn(item,len(items))
        output  += addline(columns)


    output += "</table>"
    print output
    >

    -- Venlig hilsen
    Kurt Hansen
    -- http://mail.python.org/mailman/listinfo/python-list
    chaouche yacine, Jan 6, 2013
    #15
  16. Kurt Hansen

    Kurt Hansen Guest

    Den 06/01/13 16.12, chaouche yacine skrev:
    > I'm not confident this would run on gedit. It works on a python
    > interpreter if you have a file named data.txt in the same directory
    > containing your sample data.
    >
    > It surely has to do with how gedit works then, because the "$" sign
    > isn't used in python, this business should be a gedit convention. And
    > sorry, I can't help on that, I'm not a user of gedit myself. Fortunately
    > others have answered and I beleive one of the solutions worked for you.


    It does not seem to be the case :-(

    Thank you for trying to help.

    > ------------------------------------------------------------------------
    > *From:* Kurt Hansen <>
    > *To:*
    > *Sent:* Sunday, January 6, 2013 3:21 PM
    > *Subject:* Re: How to modify this script?
    >
    > 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
    >
    >



    --
    Venlig hilsen
    Kurt Hansen
    Kurt Hansen, Jan 7, 2013
    #16
  17. Kurt Hansen wrote:

    > To convert tab-separated text lines into a HTML-table:


    As you apparently didn't receive answers that worked for you I tried to
    get what you want to work and test it in Gedit. Here's the result:

    $<
    lines = $GEDIT_SELECTED_TEXT.split("\n");
    output = '<table\>\n';

    max_columns = 0
    for line in lines:
    col_count = len(line.split("\t"))
    if col_count \> max_columns:
    max_columns = col_count

    for line in lines:
    if line == '':
    continue

    output += '<tr\>';

    columns = line.split("\t");
    if len(columns) == 1:
    output += ('<td colspan=%s\>' % max_columns) + line +
    '</td\></tr\>\n'
    continue

    for item in columns:
    output += '<td\>' + item + '</td\>'

    output += '</tr\>\n';

    output += '</table\>';
    return output
    >


    (Watch out for line wraps! I don't know how to stop Thunderbird from
    inserting them.)

    It really isn't all that difficult. The code determines the (maximum)
    number of columns present. It then processes each line; if one is found
    with exactly one column (i.e., no tabs), it applies a colspan equal to
    the maximum number of columns. This works for your test and similar data.

    As I said, this is copy/pasted from a working Gedit snippet. If it works
    for you, I'd try experimenting a bit -- what should happen when the
    number of columns is larger than 1 but less than the maximum?
    Programming isn't magic. You might start enjoying it.

    HTH,
    Gertjan.
    Gertjan Klein, Jan 7, 2013
    #17
  18. Am 06.01.2013 15:30 schrieb Kurt Hansen:
    > Den 06/01/13 15.20, Chris Angelico wrote:
    >> On Mon, Jan 7, 2013 at 1:03 AM, Kurt Hansen <> wrote:
    >>> I'm sorry to bother you, Chris, but applying the snippet with your
    >>> code in
    >>> Gedit still just deletes the marked, tab-separated text in the editor.

    >
    >> Ah, whoops. That would be because I had a bug in the code (that's why
    >> I commented that it was untested). Sorry about that! Here's a fixed
    >> version:
    >>

    > [cut]>
    >> Note that it's a single line:
    >>
    >> output += '<td colspan="' + str(4-len(columns)) + '"\>' + item +
    >> '</td\> '
    >>
    >> If your newsreader (or my poster) wraps it, you'll need to unwrap that
    >> line, otherwise you'll get an IndentError.

    >
    > Ahhh, I did'nt realize that. Now it works :)
    >
    >> That version should work.

    >
    > It certainly does. I'll keep it and use it until at better solution is
    > found.


    That would be simple:

    Replace

    output += '<td colspan="' + str(4-len(columns)) + '"\>' + item +
    '</td\> '

    with

    if len(columns) >= 3:
    output += '<td\>'
    else:
    output += '<td colspan="' + str(4-len(columns)) + '"\>'
    output += item + '</td\> '

    (untested as well; keep the indentation in mind!)


    Thomas
    Thomas Rachel, Jan 8, 2013
    #18
  19. Am 07.01.2013 18:56 schrieb Gertjan Klein:

    > (Watch out for line wraps! I don't know how to stop Thunderbird from
    > inserting them.)


    Do "insert as quotation" (in German Thunderbird: "Als Zitat einfügen"),
    or Strg-Shift-O. Then it gets inserted with a ">" before and in blue.

    Just remove the > and the space after it; the "non-breaking property" is
    kept.

    Example:

    columns = line.split("\t");
    if len(columns) == 1:
    output += ('<td colspan=%s\>' % max_columns) + line +
    '</td\></tr\>\n'
    continue

    without and

    columns = line.split("\t");
    if len(columns) == 1:
    output += ('<td colspan=%s\>' % max_columns) + line +
    '</td\></tr\>\n'
    continue

    with this feature.

    HTH,

    Thomas
    Thomas Rachel, Jan 8, 2013
    #19
  20. Well tell me how do you use this script in gedit, are you using it as a plugin ? are you putting this code somewhere ? I'll try to do the same on my side and try to understand how it works.






    ________________________________
    From: Kurt Hansen <>
    To:
    Sent: Monday, January 7, 2013 5:42 PM
    Subject: Re: Howto modify this script?

    Den 06/01/13 16.12, chaouche yacine skrev:
    > I'm not confident this would run on gedit. It works on a python
    > interpreter if you have a file named data.txt in the same directory
    > containing your sample data.
    >
    > It surely has to do with how gedit works then,because the "$" sign
    > isn't used in python, this business should be a gedit convention. And
    > sorry, I can't help on that, I'm not a user of gedit myself. Fortunately
    > others have answered and I beleive one of the solutions worked for you.


    It does not seem to be the case :-(

    Thankyou for trying to help.

    > ------------------------------------------------------------------------
    > *From:* Kurt Hansen <>
    > *To:*
    > *Sent:* Sunday, January 6, 2013 3:21PM
    > *Subject:* Re: How to modify this script?
    >
    > 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
    >
    >



    --
    Venlig hilsen
    Kurt Hansen
    --
    http://mail.python.org/mailman/listinfo/python-list
    chaouche yacine, Jan 8, 2013
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Benjamin Rutt
    Replies:
    2
    Views:
    915
    Peter Hansen
    Dec 20, 2005
  2. est
    Replies:
    3
    Views:
    265
  3. Kt Br

    modify output of script

    Kt Br, May 13, 2008, in forum: Ruby
    Replies:
    2
    Views:
    105
    Robert Klemme
    May 13, 2008
  4. tlyczko
    Replies:
    11
    Views:
    239
    tlyczko
    Nov 28, 2005
  5. DavidB
    Replies:
    5
    Views:
    127
    DavidB
    Aug 9, 2006
Loading...

Share This Page