logo-MindMajix
PostPythonPython
v
veerubhotla sowmithri

Posted on 25th July 2024|90 views

0
votes

Python Filename Without Extension

How can I get a file name without extension in python?

1 answers
Answers
P
rushi chowdary

Posted on 25th July 2024| views

In python, it is very easy to get a filename without any extension. You just need to use sliptext() like this:

import os

path="/any/file.with spaces.dot.docx"

filename = os.path.basename(path)

(file, ext) = os.path.splitext(filename)

print("Filename without any extension =", file)

print("Extension =", ext)

Output:

Filename without any extension = file.with spaces.dot

Extension = .docx

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo

  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos
Name
Course *
Email *
Phone Number