snipt

Ctrl+h for KB shortcuts

Python

unicode to HTML entity conversion for python

import cgi
cgi.escape(posts).encode('ascii', 'xmlcharrefreplace')
https://snipt.net/embed/4aa349443a3723736bcc3a55fd900774/
/raw/4aa349443a3723736bcc3a55fd900774/
4aa349443a3723736bcc3a55fd900774
python
Python
2
2019-06-22T07:51:56
True
False
False
/api/public/snipt/17268/
unicode-to-html-entity-conversion-for-python
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kn">import</span> <span class="nn">cgi</span> </span><span id="L-2"><a name="L-2"></a><span class="n">cgi</span><span class="o">.</span><span class="n">escape</span><span class="p">(</span><span class="n">posts</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;ascii&#39;</span><span class="p">,</span> <span class="s1">&#39;xmlcharrefreplace&#39;</span><span class="p">)</span> </span></pre></div> </td></tr></table>
python, zomg