I have a method:
@gen.coroutine def my_func(x): return 2 * x
mostly tornado coroutine.
I am making a list, for example:
my_funcs = [] for x in range(0, 10): f = yield my_func(x) my_funcs.append(x)
When trying to make this list comprehension, for example:
my_funcs = [yield my_func(i) for i in range(0,10)]
I realized that this is not valid syntax. It turns out that you can do this using () around the output:
my_funcs = [(yield my_func(i)) for i in range(0,10)]
- Is this behavior (the syntax for wrapping a call to
yield foo() in () such as (yield foo() ) to allow the execution of the above code) has a specific name type?- Is this some form of operator priority with
yield ?
- Is this behavior with
yield documented somewhere?
Python 2.7.11 on OSX. This code really should work like in Python2 / 3, so understanding the above list is not a good idea (see here why the comp list above works in Python 2.7 but is broken down in Python 3).
source share