How to modify this script?

Subimal Deb subimal.deb at gmail.com
Sun Jan 6 15:22:29 CET 2013


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





More information about the Python-list mailing list