weafon schrieb:
Hi guys,

I have a question about the usage of yield. As shown in the below example, in general, if there is a code segment commonly used by two or more functions, we may isolate the segment into a function and then call it from other functions if necessary.

def func1():
   ....
   while(cond):
       .....
       commoncode()
       ...


def func2():
   ....
   while(cond):
       .....
       commoncode()
       ...

def commoncode()
   AAAA
   BBBB
   CCCC

However, if there is a 'yield' operation in the common code segment, the isolation causes that func1 and func2 become a non-generator function!!


No. Not writing them as generators makes them a non-generator-function.

You are way to unspecific with your examples. But if func1 and func2 are themselves supposed to be generators, there is nothing preventing you from using them as such.

Diez
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to