Hallo,
ich hoffe, ich bin hier richtig. Ich wollte den Inhalt einer Textdatei "test":
in einer html-Tabelle haben. Von Hand ist das nervig, hab' daher ein kleines Skript geschrieben:
mit dem man mit
die Tabelle bekommt.
HTH anyone ...
Gruß
ich hoffe, ich bin hier richtig. Ich wollte den Inhalt einer Textdatei "test":
Code:
abc def ghi
jkl mno pqr
stu vwx yz
Code:
#!/usr/bin/env python
#-*- coding: iso-8859-1 -*-
# mktable.py
import os
import sys
if len(sys.argv) < 2:
print """
mktable.py
Usage: mktable.py inputfile [-s {field-separator}]
The default-field-separator is "\\t" (tabulator):
Please don't give the "-s"-option, if you want to use it.
Output is stdout: Please use ">" to redirect it to a file like in:
mktable.py inputfile > out.html
"""
sys.exit(1)
sep = "\t"
if len(sys.argv) == 4:
if sys.argv[2] == "-s":
sep = sys.argv[3]
try:
fh = file(sys.argv[1], "r")
a = fh.readlines()
fh.close
except IOError:
print "Error reading input-file."
sys.exit(1)
if len(a) == 0:
print "Input-file empty. Nothing done."
sys.exit(1)
b = ["<table border>"]
for i in a:
i = i.rstrip("\n")
c = i.split(sep)
b.append("<tr>")
for u in c:
b.append("<td>" + u + "</td>")
b.append("</tr>")
b.append("</table>")
for i in b:
print i
Code:
mktable.py test -s " " > out.html
HTH anyone ...
Gruß