Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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

python os filename without extension

os.path.splitext('filename.txt')[0]
# filename
Comment

PREVIOUS NEXT
Code Example
Python :: get a list of ids from queryset django 
Python :: pandas drop rows with value in list 
Python :: python max value of list of tuples 
Python :: install nltk in python 
Python :: plt imshow python 
Python :: dataframe fillna with 0 
Python :: python extract value from a list of dictionaries 
Python :: smtp email template 
Python :: hello world py 
Python :: get working directory in python 
Python :: static class python 
Python :: load saved model tensorflow 
Python :: python selenium clear input 
Python :: how to make a randomized pasword genirator in python 
Python :: download a file from url python 
Python :: sort the dictionary in python 
Python :: python replace string in file 
Python :: pil image to numpy array 
Python :: how to reference a file in python 
Python :: how to print a string by reverse way in python 
Python :: blinking an led with raspberry pi 
Python :: how to generate random normal number in python 
Python :: value_count pandas change column name 
Python :: python regex cheat sheet 
Python :: start virtualenv 
Python :: python for loop in one line 
Python :: python print combinations of string 
Python :: python list comprehension with if 
Python :: Adding new column to existing DataFrame in Pandas by assigning a list 
Python :: pyspark check all columns for null values 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =