Question : Python: how to retrieve substring from file name

hi experts,

With the attached code snippt I have found those files that I wanted. There files are

file name: -->: OUT20090121155642-PartnerL-x7xT
file name: -->: OUT20090121160716-PartnerL-UdTp
file name: -->: OUT20090121155138-PartnerL-ZQpz

Now from the file names I want to get
1556
1607
1551
These are hours and minutes. How to retrieve them? I tried filename.index(3, 14) but it did not work.

Thanks for any replies.
Code Snippet:
1:
2:
3:
4:
dir = '/home/talog_data/'
        for filename in  os.listdir(dir):
            if re.search('PartnerL', filename):
                print "file name: -->:", filename
Open in New Window Select All

Answer : Python: how to retrieve substring from file name

This outputs 1556:
1:
2:
3:
fn = 'OUT20090121155642-PartnerL-x7xT'
hhmm = fn[11:11+4]
print(hhmm) # 1556
Open in New Window Select All
Random Solutions  
 
programming4us programming4us