>>> import os
>>> pth="/abeja/blanca/zumbas/ebria/de/miel/en/mi/alma/y.te.tuerces"
>>> os.path.split(os.path.dirname(pth))[1]
'alma'
>>>
Mostly Linux & Python syntax notes and hyperlinks.
Thursday, June 23, 2011
python: get the last directory name in a path
If I want to pull just the parent directory name out of a long path to a file:
Friday, June 17, 2011
python: create a dummy file in one line
open('onestep.txt','w').close()
from a comment on http://rogermcd.wordpress.com/2008/07/20/creating-a-file-with-python/
Subscribe to:
Posts (Atom)