Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get string before hyphen

Tags:

python

I have below filename:

pagecounts-20150802-000000

I want to extract the date out of above 20150802 I am using the below code but its not working:

print os.path.splitext("pagecounts-20150802-000000")[0]
like image 635
Aquarius24 Avatar asked Dec 05 '22 20:12

Aquarius24


1 Answers

The methods in os.path are mainly used for path string manipulation. You want to use string splitting:

print 'pagecounts-20150802-000000'.split('-')[1]
like image 69
alexgolec Avatar answered Dec 22 '22 06:12

alexgolec