Python os.path
module extracts the base name or directory name conveniently.
>>> import os.path >>> os.path.basename("c:/python/test/tp.py")
'tp.py'
>>> os.path.dirname("c:/python/test/tp.py")
'c:/python/test'Note: always use
/
instead of \
even in Windows system.