comparing elements of a list with a string

Shriphani shriphanip at gmail.com
Tue Sep 25 11:39:45 EDT 2007


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?

Regards,
Shriphani Palakodety




More information about the Python-list mailing list