Path manipulation
Question: Consider you are launching a script in the following linux path:  
`/home/chris/sources/a/b/c/d/e/test.py`

I want to be able to check whether folder named `sources` is in path and then
return the path `/home/chris/sources/`

Do you think I should do it using simple string manipulation, or do we have in
python some xpath library that can help me do it?


Answer: inb4Padraic

    
    
    path = '/home/chris/sources/a/b/c/d/e/test.py'.split('/')
    if 'sources' in path:
        print '/'.join(path[:path.index('sources') + 1])
    

another way

    
    
    import os
    
    path = '/home/chris/sources/a/b/c/d/e/test.py'.split('sources')
    if len(path) > 1:
        print os.path.join(path[0], 'sources')
    

