snipt

Ctrl+h for KB shortcuts

Python 3

file extension or '' if there is not one

(filename.rsplit('.', 1)[1:] or [''])[0]
https://snipt.net/embed/40b58c25e7bbf0de7eec7f7edc2b64bf/
/raw/40b58c25e7bbf0de7eec7f7edc2b64bf/
40b58c25e7bbf0de7eec7f7edc2b64bf
python3
Python 3
1
2019-07-16T10:33:21
True
False
False
/api/public/snipt/5369/
file-extension-or-if-there-is-not-one
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="p">(</span><span class="n">filename</span><span class="o">.</span><span class="n">rsplit</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]</span> <span class="ow">or</span> <span class="p">[</span><span class="s1">&#39;&#39;</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span> </span></pre></div> </td></tr></table>
extension, file, python