I have a lot of strings like this
/home/build_targets/JavaFiles/Commonfeature/CM/src/com/ems/ClusterGroupTreePanel.java I need to get the file name ClusterGroupTreePanel.java out.
Is there an efficient way to achieve this in Python?
use os.path.basename
>>> import os.path >>> os.path.basename('/home/build_targets/JavaFiles/Commonfeature/CM/src/com/ems/ClusterGroupTreePanel.java') 'ClusterGroupTreePanel.java' Generally, if your question goes something like "How do I manipulate this filesystem path name in an interesting way?". The answer is usually "use some combination of functions in the os.path module". There's lots of great stuff in there and it would be well worth your time to familiarize yourself with the different functions.
os.path.basename(path) will give you the file name, if you want to leave it out you can use os.path.split and take the first part
os.path.split(full_path)[0]