comparing elements of a list with a string
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Fri Sep 28 00:23:25 EDT 2007
En Thu, 27 Sep 2007 07:44:08 -0300, Shriphani <shriphanip at gmail.com>
escribi�:
> def listAllbackups(filename):
> list_of_backups = glob(home+'/Desktop/backupdir/*%s*'%filename)
> for element in list_of_back:
> if element.find(file) != -1:
> date_components = element.split('-')[-4:-1]
> date = str(date_components[0]) + ":" + str(date_components[1]) +
> ":" + str(date_components[2])
> time = element.split('-')[-1]
> yield (date, time)
> print listAllbackups('fstab')
>
>
> I ran it in the terminal and I got:
>
> <generator object at 0x81ed58c>
>
> Why does it do that and not just print out all the values of (date,
> time)
Because listAllbackups is a generator function: each time someone asks it
the next value, it runs until the "yield" statement, and pauses. Next time
execution continues from the same point.
You have to iterate over it. Try:
for date,time in listAllbackups('fstab'):
print date,time
or
items = list(listAllbackups('fstab'))
print items
--
Gabriel Genellina
More information about the Python-list
mailing list