Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a part of a path separated with dots

Tags:

python

string

Given a path, e.g.

file_path = 'a.b.c.d.e'

I wish to remove the e.
This is what I did:

class_path = ('.').join(file_path.split('.')[0:-1])

Any more elegant way to do it?

like image 403
Zusman Avatar asked Jul 02 '19 11:07

Zusman


1 Answers

import os
os.path.splitext(file_path)[0]
like image 125
ipaleka Avatar answered Oct 13 '22 00:10

ipaleka