Quantcast
Channel: How do I get the filename without the extension from a path in Python? - Stack Overflow
Viewing all articles
Browse latest Browse all 66

Answer by Zéiksz for How to get the filename without the extension from a path in Python?

$
0
0

On Windows system I used drivername prefix as well, like:

>>> s = 'c:\\temp\\akarmi.txt'
>>> print(os.path.splitext(s)[0])
c:\temp\akarmi

So because I do not need drive letter or directory name, I use:

>>> print(os.path.splitext(os.path.basename(s))[0])
akarmi

Viewing all articles
Browse latest Browse all 66

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>