list comprehension to do os.path.split_all ?

Emile van Sebille emile at fenx.com
Thu Jul 28 23:15:57 CEST 2011


On 7/28/2011 1:18 PM gry said...
> [python 2.7] I have a (linux) pathname that I'd like to split
> completely into a list of components, e.g.:
>     '/home/gyoung/hacks/pathhack/foo.py'  -->   ['home', 'gyoung',
> 'hacks', 'pathhack', 'foo.py']
>
> os.path.split gives me a tuple of dirname,basename, but there's no
> os.path.split_all function.
>

Why not just split?

'/home/gyoung/hacks/pathhack/foo.py'.split(os.sep)

Emile




More information about the Python-list mailing list