Created
September 6, 2013 21:22
-
-
Save vanous/6470179 to your computer and use it in GitHub Desktop.
generate docbook table from tab separated text
python script for codeskulptor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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