How to modify this script?

Chris Angelico rosuav at
Sun Jan 6 15:20:25 CET 2013

On Mon, Jan 7, 2013 at 1:03 AM, Kurt Hansen <kurt at ugyldig.invalid> 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

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.


More information about the Python-list mailing list