Python: Extract time from a file path -
i find general way extract time in format %h-%m-%s different file path follow:
u'c:/users/pivo/work/data/pink_exp_2015_12031329\\2015-12-03_15-58-29_trdata.txt' u'c:/users/pivo/work/data/black_try\\2015-12-03_14-41-00_trdata.txt'
i can use split , point time, 2 cases works follow looking general solution
date_str = path1.split('_')[2] date_str = path2.split('_')[4]
what's best way that? thank you
import re reg = r'\d+\-\d+\-\d+' data='c:/users/pivo/work/data/black_try\\2015-12-03_14-41-00_trdata.txt' a=re.findall(reg, data) print(a[1])
you need try doing regex patterns find absolutely want.
here python regex tutorial: http://www.tutorialspoint.com/python/python_reg_expressions.htm
Comments
Post a Comment