How do I take a directory name from a given dir?

Mike Kent mrmakent at cox.net
Mon May 1 15:53:51 EDT 2006


Python 2.4.2 (#1, Nov 29 2005, 14:04:55)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> d = "/home/testuser/projects"
>>> os.path.basename(d)
'projects'
>>> os.path.dirname(d)
'/home/testuser'
>>>




More information about the Python-list mailing list