Answers for "python get file basename"

6

how to get just the filename in python

import os
>>> base=os.path.basename('/root/dir/sub/file.ext')
>>> base
'file.ext'
>>> os.path.splitext(base)
('file', '.ext')
>>> os.path.splitext(base)[0]
'file'
Posted by: Guest on May-19-2020
0

python file basename

#basename with extension
basename = os.path.basename(path)
Posted by: Guest on December-05-2020

Python Answers by Framework

Browse Popular Code Answers by Language