What I’m hoping for is something like this:
Input:
a
aa
b
bb
Output:
<li>a</li>
<li>aa</li>
<li>b</li>
<li>bb</li>
So I try it in python, right:
file = open('/Users/Shannon/Desktop/add_tags.txt')
while 1:
line = file.readline()
if not line:
break
else:
print "<li>" + line + "</li> \n"
And the result is a garbled mess like so:
</li> e sleep patterns when possibleresult in positive outcomes
Then I try it in php:
<html><body>
<?php
$fin = fopen('add_tags.txt', 'r');
while(!feof($fin))
{
$input_string = fgets($fin);
$output_string = "<li>".$input_string."</li>";
echo $output_string;
}
?>
But the li tags render as bullet points, naturally. So I added backslashes to escape the brackets, but that appeared to have no effect. Then I changed “(lessthan) li (greaterthan)” to “x” just to see what happened – nothing. Still a bulleted list. I have no idea. Something tells me that switching to java won’t solve my problems. Any ideas?
Here’s the python solution in two lines:
And two comments:
The ‘for line in…’ style is much cleaner and easier (open(filename) returns a python generator, yielding one line at a time).
To get rid of trailing ‘\n’ in the end of the lines, I used rstrip(). This also gets rid of extra spaces at the end of the line (which won’t make any difference in the HTML, anyway).