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-08-18T02:37:43
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

Python

return a string starting w/the last occurrence of '/'

mystring = "http://some.domain/foo/bar/returnedstring"
mystring[-(mystring[::-1].find('/')):]
https://snipt.net/embed/06f35208aac725e4436748e89da6b996/
/raw/06f35208aac725e4436748e89da6b996/
06f35208aac725e4436748e89da6b996
python
Python
3
2019-08-17T03:33:57
True
False
False
/api/public/snipt/690/
return-a-string-starting-wthe-last-occurrence-of
<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="n">mystring</span> <span class="o">=</span> <span class="s2">&quot;http://some.domain/foo/bar/returnedstring&quot;</span> </span><span id="L-2"><a name="L-2"></a><span class="n">mystring</span><span class="p">[</span><span class="o">-</span><span class="p">(</span><span class="n">mystring</span><span class="p">[::</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)):]</span> </span></pre></div> </td></tr></table>
python, string-manip