Q:

Parse files names given specific format in Python

I would like to create a DataFrame parsing the name of some files that have a particular format. 
filename format : 
event_A_(number)_(start datetime)_(end datetime)_(code)_(category).txt
datetime format : YYYY-MM-DD_HH-MM_SS
name file example : event_A_12_2019-01-22_01-35_20_2019-01-22_19-15_13_b123_aa.txt
I've tried using split, then simple regex and then merging strings, but it has to be a simple way to do it.  Any suggestions on how to accomplish this?
This is how I manage to do it, but I believe there should be a simpler way:
lst_split = file.split('_')
#number = re.findall(r"_A_(..)",file)
number = lst_split[2]
start_date = lst_split[3]
tmp = lst_split[4] + ":" + lst_split[5]
start_time = tmp.replace('-',':')
end_date = lst_split[6]
tmp = lst_split[7] + ":" + lst_split[8]
end_time = tmp.replace('-',':')
code = lst_split[9]
tmp = (lst_split[10]).split('.')
category = tmp[0]
print(number,start_date,start_time,end_date,end_time,code,category)

A:

You can use unpacking to place all the parts into variables.  Then you'll have clearer code and fewer transformations to do:
file = "event_A_12_2019-01-22_01-35_20_2019-01-22_19-15_13_b123_aa.txt"
_,_,number,start_date,startHM,startS,end_date,endHM,endS,code,category = file.split("_")
start_time = f"{startHM}:{startS}".replace("-",":")
end_time   = f"{endHM}:{endS}".replace("-",":")
category   = category.strip(".txt")
print(number,start_date,start_time,end_date,end_time,code,category)

# 12 2019-01-22 01:35:20 2019-01-22 19:15:13 b123 aa

note that you could also break it down using a (rather unwieldy) regular expression but you would still have to do the separator substitutions on the components.

