How to split path and file name in Python

Suppose you have a path, for example


Now you want to split the path and the file name, you want to split it into the following two parts


The idiomatic way to do this is using os.path.split method

>>> import os
>>> path,filename=os.path.split("/host/name/public_html/lib/general_functions.php")
>>> path
>>> filename

The os.path.split is smart enough to accept both unix style path and windows style:

>>> path,filename=os.path.split("c:\\host\\name\\public_html\\lib\\general_functions.php")
>>> path
>>> filename