Python Filename Without Extension

Python

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

1
Answers

Replies

A regex should not be used in most of the cases.


os.path.splitext(filename)[0]


This will also be responsible to handle a filename like .bashrc correctly by keeping the whole name.

 
 

If you want to unleash your potential in this competitive field, please visit the Python course page for more information, where you can find the Python tutorials and Python frequently asked interview questions and answers as well.

 

This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.