String code required please

da_hmea98 at hotmail.com da_hmea98 at hotmail.com
Fri Oct 14 01:07:38 EDT 2005


dapgy at yahoo.com wrote:
> Does someone have the Python code to pull just the filename and
> extension from the end of an absolute path please.
>
> Thanks in advance ...

# Here you go...
import os.path

# Example path
p1 = "C:\\WINDOWS\\system32\\DirectX\\Dinput\\mse.ini"

# This will return: 'mse.ini'
os.path.basename(p1)

"""
You can read more about manipulating file paths by reading the Python
documentation under "6.2 os.path -- Common pathname manipulations".

DA
"""




More information about the Python-list mailing list