Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to get file name without extension 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'
Comment

python get filename without extension

os.path.splitext(file)[0]
Comment

python get filename without extension

#Using pathlib in Python 3.4+
from pathlib import Path
Path('/root/dir/sub/file.ext').stem
Comment

python filename without extension

# OPTION 1
import os
name = os.path.basename('/root/dir/sub/file.ext').split(".")[0]		# returns >file<

# OPTION 2
from pathlib import Path
Path('/root/dir/sub/file.ext').stem		# returns >file<
# Note that if your file has multiple extensions .stem will only remove the last extension.
# For example, Path('file.tar.gz').stem will return 'file.tar'.
Comment

PREVIOUS NEXT
Code Example
Python :: python selenium assert presence of an element 
Python :: python define 2d table 
Python :: python compare if 2 files are equal 
Python :: pandas change frequency of datetimeindex 
Python :: read binary file python 
Python :: dask show progress bar 
Python :: python pandas replace nan with null 
Python :: matplotlib show percentage y axis 
Python :: convert list to binary python 
Python :: b1-motion tkinter 
Python :: plotly hide trace from hover 
Python :: where my python modules 
Python :: python datetime last day of month 
Python :: django all urls 
Python :: numpy correlation 
Python :: discordpy 
Python :: multivariate outlier detection python 
Python :: scatter plot plotly 
Python :: pyspark dataframe to single csv 
Python :: colab read xlsx 
Python :: shift axis in python 
Python :: python text fromatting rows 
Python :: message tags in django 
Python :: timed loop python 
Python :: iterar una lista en python 
Python :: add font to the label in window tkinter 
Python :: read only the first line python 
Python :: read xls file in python 
Python :: how to use selenium on default chrome python 
Python :: RuntimeError: Please set pin numbering mode using GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM) 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =