Brand new to python and am running into an annoying formatting issue. I wrote a script that logs onto Confluence and posts content. Unfortunately, the Confluence page only recognizes HTML5 syntax and getting this formatted is taking me wayyy longer than I expected.
I edited the script to replace all \n
characters with br \
characters, which gets me to something ugly, but respectable. To really tidy things up, I'd ideally like to just stick this entire thing inside a table.
I already outlined the HTML5 code that I want below, but I don't know the easiest/most efficient way of prepending these tags to my string header1 header 2 header3 header4 header 5 10 15 20 27 to/path/foo.c 7 67 10 22 to/path/boo.c ...etc
without using some external Python module/library. Using Python 2.7.5, I believe.
HTML5 code to produce table below
<table style="width:100%" \>
<tr \>
<th \>Header1
<th \>Header2
<th \>Header3
<th \>Header4
<th \>Header5
<tr \>
<td \>10
<td \>15
<td \>20
<td \>27
<td \>to/path/foo.c
<tr \>
<td \>7
<td \>67
<td \>10
<td \>22
<td \>to/path/boo.c
<tr \>
<td \>1
<td \>2
<td \>3
<td \>4
<td \>to/path/moo.c
<tr \>
<th \> Sum:
<tr \>
<td \>18
<td \>84
<td \>33
<td \>53
myDesiredTableFormat
Header1 Header2 Header3 Header4 Header5
10 15 20 27 to/path/foo.c
7 67 10 22 to/path/boo.c
1 2 3 4 to/path/moo.c
Sum:
18 84 33 53
The way I am thinking of writing this script is:
- A nested for-loop (i.e. for every line/for every word)
- Prepend
<table style="width:100%" \><tr \>
to the variable that will store this table - If word = header or sum...prepend
<th \>
- Else word = number or file path...prepend
<td \>
- Replace
\n
with<br \><tr \>
.
Please tell me there is an easier, more efficient (or elegant way) to convert a string to an HTML5 table in Python (i.e. without using modules that I have to download...imports with the language are fine).
10 15 20 27 to/path/foo.c
7 67 10 22 to/path/boo.c ...etc` right now. This gives me something that looks like a table, but it's not aligned like a table should be. – MrPickles Jul 07 '15 at 02:18
` syntax is incorrect. What you are trying to use are self-closing tags but there are several things wrong. First, your slashes are backwards. Self closing tags look like this: `
`. Second, you do not need them in HTML5. Third, you never need them on tags that already have a closing tag. (`
` has no close tag, it stands alone. `