How to get a line before a hyphen

I have a file name:

pagecounts-20150802-000000

I want to extract the date from above. 20150802 I use the code below, but its not working:

print os.path.splitext("pagecounts-20150802-000000")[0]
+4
source share
1 answer

Methods are os.pathmainly used to manipulate a path string. You want to use line splitting:

print 'pagecounts-20150802-000000'.split('-')[1]
+11
source

Source: https://habr.com/ru/post/1608225/


All Articles