option end="" in python print() function does not work consistently
<p>The following python code:</p>

<pre><code>import xml.sax

class C_Handler(xml.sax.ContentHandler):

    def startDocument(self):
        print("&lt;html&gt;&lt;head&gt;&lt;title&gt;Lieferungen&lt;/title&gt;&lt;/head&gt;")
        print("&lt;body&gt;&lt;h1&gt;Lieferungen&lt;/h1&gt;&lt;hr&gt;\n")
        print("&lt;table border=\"1\"&gt;&lt;tr&gt;&lt;th&gt;Nummer&lt;/th&gt;&lt;th&gt;Artikel&lt;/th&gt;&lt;th&gt;preis&lt;/th&gt;&lt;th&gt;Lieferant&lt;/th&gt;&lt;/tr&gt;\n")


    def startElement(self, tag, attributes): 
        if tag == "artikel":
            print("&lt;tr&gt;&lt;td&gt;{}&lt;/td&gt; &lt;td&gt;".format(attributes["id"]),end="")
        if tag == "preis":
            print("&lt;/td&gt; &lt;td&gt;", end="")
        if tag == "lieferant":
            print("&lt;/td&gt; &lt;td&gt;", end="")

    def endElement(self, tag):
        if tag == "lieferant":
            print("&lt;/td&gt; &lt;/tr&gt;")

    def characters(self, content):
        print("{}".format(content), end="")

    def endDocument(self):
        print("\n&lt;/table&gt;\n&lt;/body&gt;\n&lt;/html&gt;\n")

if ( __name__ == "__main__"):

    c = C_Handler()

    xml.sax.parse("lieferungen.xml", c)
</code></pre>

<p>is supposed to transform the following xml-file:</p>

<pre><code>&lt;?xml version="1.0"?&gt;
&lt;lieferungen&gt;
     &lt;artikel id="3526"&gt;
         &lt;name&gt;apfel&lt;/name&gt;
         &lt;preis stueckpreis="true"&gt;8.97&lt;/preis&gt;
         &lt;lieferant&gt;Fa. Krause&lt;/lieferant&gt;
     &lt;/artikel&gt;
&lt;/lieferungen&gt;
</code></pre>

<p>into the following output:</p>

<pre><code>&lt;html&gt;&lt;head&gt;&lt;title&gt;Lieferungen&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;&lt;h1&gt;Lieferungen&lt;/h1&gt;&lt;hr&gt;

&lt;table border="1"&gt;&lt;tr&gt;&lt;th&gt;Nummer&lt;/th&gt;&lt;th&gt;Artikel&lt;/th&gt;&lt;th&gt;preis&lt;/th&gt;&lt;th&gt;Lieferant&lt;/th&gt;&lt;/tr&gt;

&lt;tr&gt;&lt;td&gt;3526&lt;/td&gt; &lt;td&gt; apfel &lt;/td&gt; &lt;td&gt; 8.97 &lt;/td&gt; &lt;td&gt; Fa. Krause &lt;/td&gt; &lt;/tr&gt;

&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>However, what I get is this:</p>

<pre><code>&lt;html&gt;&lt;head&gt;&lt;title&gt;Lieferungen&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;&lt;h1&gt;Lieferungen&lt;/h1&gt;&lt;hr&gt;

&lt;table border="1"&gt;&lt;tr&gt;&lt;th&gt;Nummer&lt;/th&gt;&lt;th&gt;Artikel&lt;/th&gt;&lt;th&gt;preis&lt;/th&gt;   &lt;th&gt;Lieferant&lt;/th&gt;&lt;/tr&gt;


     &lt;tr&gt;&lt;td&gt;3526&lt;/td&gt; &lt;td&gt; 
        apfel  
       &lt;/td&gt; &lt;td&gt; 8.97  
       &lt;/td&gt; &lt;td&gt; Fa. Krause &lt;/td&gt; &lt;/tr&gt;

&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>In other words: the end="" option in the print function does not work as expected. What is strange is this:
Sometimes it works (after "Fa. Krause") and in other cases (e.g. after "apfel") it does not work. Since both "Fa. Krause" and "apfel" are character data, the characters() method is applied in each case by the content handler. Still, the result is not the same, which makes this whole thing extremely weird.</p>