Why are these strings escaping from my regular expression in python?
Posted
by
dohkoxar
on Stack Overflow
See other posts from Stack Overflow
or by dohkoxar
Published on 2011-01-08T21:40:11Z
Indexed on
2011/01/08
21:53 UTC
Read the original article
Hit count: 189
In my code, I load up an entire folder into a list and then try to get rid of every file in the list except the .mp3 files.
import os
import re
path = '/home/user/mp3/'
dirList = os.listdir(path)
dirList.sort()
i = 0
for names in dirList:
match = re.search(r'\.mp3', names)
if match:
i = i+1
else:
dirList.remove(names)
print dirList
print i
After I run the file, the code does get rid of some files in the list but keeps these two especifically:
['00. Various Artists - Indie Rock Playlist October 2008.m3u', '00. Various Artists - Indie Rock Playlist October 2008.pls']
I can't understand what's going on, why are those two specifically escaping my search.
© Stack Overflow or respective owner