Return a string result with out breaking loop

cnb circularfunc at yahoo.se
Tue Aug 26 02:50:19 CEST 2008


def somefunc():
       for action, files in results:
               full_filename = os.path.join(path_to_watch, files)
               theact = ACTIONS.get(action, "Unknown")
               yield  str(full_filename) +  " " + str(theact)



?


Here is an example if that doesn't work, using yield, to show how to
use yield:
def yi(x):
	while x > 0:
		yield str(x)
		x -= 1


>>> yi(4)
<generator object at 0x01FA3C88>
>>> a=yi(4)
>>> a.next()
'4'
>>> a.next()
'3'
>>> a.next()
'2'
>>> a.next()
'1'
>>> a.next()

Traceback (most recent call last):
  File "<pyshell#151>", line 1, in <module>
    a.next()
StopIteration
>>>



More information about the Python-list mailing list