Delete Specific Part Of A String
<p>I want to delete the part after the last <code>'/'</code> of a string in this following way:</p>

<pre><code>str = "live/1374385.jpg"
formated_str = "live/"
</code></pre>

<p>or</p>

<pre><code>str = "live/examples/myfiles.png"
formated_str = "live/examples/"
</code></pre>

<p><strong>I have tried this so far ( working )</strong></p>

<pre><code>import re
for i in re.findall('(.*?)/',str):
    j += i
    j += '/'
</code></pre>

<p>Output : </p>

<p><code>live/</code> or <code>live/examples/</code></p>

<p>I am a beginner to python so just curious is there any other way to do that .</p>

<pre><code>#!/usr/bin/python

def removePart(_str1):
    return "/".join(_str1.split("/")[:-1])+"/"

def main():
    print removePart("live/1374385.jpg")
    print removePart("live/examples/myfiles.png")

main()
</code></pre>

python string substring