Skip to content

Instantly share code, notes, and snippets.

@vanous
Created September 6, 2013 21:22
Show Gist options
  • Save vanous/6470179 to your computer and use it in GitHub Desktop.
Save vanous/6470179 to your computer and use it in GitHub Desktop.
generate docbook table from tab separated text python script for codeskulptor
input="""img.png description
bbb 222
ccc 333
ddd 444
eee 555
fff 666"""
#define number of columns
cols=3
def process(input):
#split into lines
output=input.split('\n')
#map
for i in range(0, len(output),cols):
print "<row>"
#split lines into columns
for col in range(0,cols):
print " <entry><para><mediaobject><imageobject><imagedata fileref=\"images/%s\" align=\"center\" width=\"100%\" /></imageobject></mediaobject></para></entry>" % str(output[i+col].split('\t')[0])
print "</row>"
print "<row>"
for col in range(0,cols):
print " <entry><para>", str(output[i+col].split('\t')[1]), "</para></entry>"
print "</row>"
process(input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment