Python, html and writing to a text file
<p>I'm creating an html string and writing it to a an .html file. I'm pulling data from websites with json and xml. This pulls text and links and places them into a triple quoted string. There is more to this html string but this much will show the problem. I have a function that takes the news string and writes the string to a .html file. I know that all the inserting of the data works because before I send the string to the write to file function I have it print to screen and have copied it to a text file and displayed it on the browser and it displays properly with all the correct data. The problem occurs when python writes to the file. I get a "has to be string error".</p>

<p>It was writing to the file just fine when the only data was text but once it started to be urls it would fail to write. Well, it would not fell to write every single time but once is enough. </p>

<p>I have a theory. Some urls contain escape characters or some such(haven't been programming too long). Or maybe the data that I'm inserting need to be put in triple quotes before inserting it to the html string. I'm not sure that is even possible. </p>

<p>I have tried inserting the data using this: news % (data,data,data) but it doesn't solve the problem.</p>

<pre><code>news = ("""&lt;div id='weather'&gt;""" +
   """&lt;center&gt;&lt;h1&gt;Weather&lt;/h1&gt;&lt;/center&gt;""" +
   """&lt;center&gt;&lt;cite&gt;Weatherunderground&lt;/cite&gt;&lt;/center&gt;""" +        
   """&lt;hr /&gt;""" +
   """&lt;h6&gt;""" + weather['forecast']['txt_forecast']['forecastday'][0]['title'] + """&lt;/h6&gt;""" +
   """&lt;p&gt;""" + weather['forecast']['txt_forecast']['forecastday'][0]['fcttext'] + """&lt;/p&gt;""" +
   """&lt;h6&gt;Forecast&lt;/h6&gt;"""
   """&lt;table border='1'&gt;"""
   """&lt;tr&gt;"""
   """&lt;th style='font-size: small;'&gt;""" + weather['forecast']['simpleforecast']['forecastday'][0]['date']['weekday'] + """&lt;/th&gt;""" +
   """&lt;th style='font-size: small;'&gt;""" + weather['forecast']['simpleforecast']['forecastday'][1]['date']['weekday'] + """&lt;/th&gt;""" +
   """&lt;th style='font-size: small;'&gt;""" + weather['forecast']['simpleforecast']['forecastday'][2]['date']['weekday'] + """&lt;/th&gt;""" +
   """&lt;th style='font-size: small;'&gt;""" + weather['forecast']['simpleforecast']['forecastday'][3]['date']['weekday'] + """&lt;/th&gt;""" +
   """&lt;/tr&gt;""" +
   """&lt;tr&gt;""" +
   """&lt;td style='font-size: small;'&gt;""" + weather['forecast']['simpleforecast']['forecastday'][0]['conditions'] + """&lt;/td&gt;""" +
   """&lt;td style='font-size: small;'&gt;""" + weather['forecast']['simpleforecast']['forecastday'][0]['conditions'] + """&lt;/td&gt;""" +
   """&lt;td style='font-size: small;'&gt;""" + weather['forecast']['simpleforecast']['forecastday'][0]['conditions'] + """&lt;/td&gt;""" +
   """&lt;td style='font-size: small;'&gt;""" + weather['forecast']['simpleforecast']['forecastday'][0]['conditions'] + """&lt;/td&gt;""" +
   """&lt;/tr&gt;""" +
   """&lt;tr&gt;""" +
   """&lt;td style='font-size: small;'&gt;high """ + weather['forecast']['simpleforecast']['forecastday'][0]['high']['fahrenheit'] + """&lt;/td&gt;""" +
   """&lt;td style='font-size: small;'&gt;high """ + weather['forecast']['simpleforecast']['forecastday'][0]['high']['fahrenheit'] + """&lt;/td&gt;""" +
   """&lt;td style='font-size: small;'&gt;high """ + weather['forecast']['simpleforecast']['forecastday'][0]['high']['fahrenheit'] + """&lt;/td&gt;""" +
   """&lt;td style='font-size: small;'&gt;high """ + weather['forecast']['simpleforecast']['forecastday'][0]['high']['fahrenheit'] + """&lt;/td&gt;""" +
   """&lt;/tr&gt;""" +
   """&lt;tr&gt;""" +
   """&lt;td style='font-size: small;'&gt;low """ + weather['forecast']['simpleforecast']['forecastday'][0]['low']['fahrenheit'] + """&lt;/td&gt;""" +
   """&lt;td style='font-size: small;'&gt;low """ + weather['forecast']['simpleforecast']['forecastday'][0]['low']['fahrenheit'] + """&lt;/td&gt;""" +
   """&lt;td style='font-size: small;'&gt;low """ + weather['forecast']['simpleforecast']['forecastday'][0]['low']['fahrenheit'] + """&lt;/td&gt;""" +
   """&lt;td style='font-size: small;'&gt;low """ + weather['forecast']['simpleforecast']['forecastday'][0]['low']['fahrenheit'] + """&lt;/td&gt;""" +
   """&lt;/tr&gt;""" +
   """&lt;/table&gt;""" +
   """&lt;/div&gt;""" +
   """&lt;hr /&gt;""" +
   """&lt;div id='kindle'&gt;""" +
   """&lt;center&gt;&lt;h1&gt;Amazon Daily Kindle Deal&lt;/h1&gt;&lt;/center&gt;""" +
   """&lt;center&gt;&lt;cite&gt;amazon&lt;/cite&gt;&lt;/center&gt;""" +
   """&lt;hr /&gt;""" +
   """&lt;div class='firstHeadline'&gt;""" +
   """&lt;h3&gt;""" + kind[0][0] + """&lt;/h3&gt;""" +
   """&lt;p class='content'&gt;""" + kind[1][0] + """&lt;/p&gt;""" +
   """&lt;p class='url'&gt;&lt;a href='""" + kind[2][0] + """'&gt;""" + kind[2][0] + """&lt;/a&gt;&lt;/p&gt;""" +
   """&lt;/div&gt;""" +
   """&lt;hr /&gt;""" +
   """&lt;/div&gt;""" +
   """&lt;div id='amazonApp'&gt;""" +
   """&lt;center&gt;&lt;h1&gt;Amazon App of the Day&lt;/h1&gt;&lt;/center&gt;""" +
   """&lt;center&gt;&lt;cite&gt;amazon&lt;/cite&gt;&lt;/center&gt;""" +
   """&lt;hr /&gt;""" +
   """&lt;div class='firstHeadline'&gt;""" +
   """&lt;h3&gt;""" + app[0][0] + """&lt;/h3&gt;""" +
   """&lt;p class='content'&gt;""" + app[1][0] + """&lt;/p&gt;""" +
   """&lt;p class='url'&gt;&lt;a href='""" + app[2][0] + """'&gt;""" + app[2][0] + """&lt;/a&gt;&lt;/p&gt;""" +
   """&lt;/div&gt;""" +
   """&lt;hr /&gt;""" +
   """&lt;/div&gt;""")
</code></pre>
