Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python get the file name with os.path lib [duplicate]

Tags:

python

Hello how can I get the file name with os.path lib? For example:

C:\Users\filippo\Desktop\K.java

I want the K without the extension file

like image 673
Filippo Avatar asked Dec 21 '15 11:12

Filippo


1 Answers

I suggest you use the splitext and basename functions from os.path

K, ext = os.path.splitext(os.path.basename(my_path))

See the docs here.

like image 68
qwattash Avatar answered Oct 03 '22 10:10

qwattash