comparing elements of a list with a string
Matimus
mccredie at gmail.com
Tue Sep 25 12:18:30 EDT 2007
Shriphani wrote:
> Hello all,
> I have a problem here. I have a list named list_of_files which
> contains filenames with their timestamps attached to the name. If I
> have a string "fstab", and I want to list out the files in whose names
> the word fstab appears should I go about like this :
>
> def listAllbackups(file):
> list_of_files = os.listdir("/home/shriphani/backupdir")
> for element in list_of_files:
> if element.find(file) != -1:
> date = ###
> time = ####
> return (date, time)
>
> The major trouble is that the return statement causes it to exit after
> attempt one. How do I use the yield statement here?
I would just do this:
[code]
from glob import glob
def listallbackupfiles(filename):
return glob("/home/shriphani/backupdir/*%s*"%filename)
[/code]
More information about the Python-list
mailing list