I need to extract file name without extension name.
example.
/home/si/text.txt
/home/si/text.vx.txt
In the both case I should receive output text only. I am not sure how many trailing extension file can have but I need to extract only file name. I have tried spliitext(filename)[0] but it gave me output text.vx rather than text
This should work for your needs:
from os.path import basename
print basename("/home/si/text.vx.txt").split('.')[0]
>>> text
I use split function after getting file name.
filename.split('.')[0]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.