In Python 3.6, I am able to use yield inside a coroutine. However I am not able to use yield from.
Below is my code. On line 3 I await another coroutine. On line 4 I try to yield from a file. Why won't Python 3.6 allow me to do that?
async def read_file(self, filename): with tempfile.NamedTemporaryFile(mode='r', delete=True, dir='/tmp', prefix='sftp') as tmp_file: await self.copy_file(filename, tmp_file) yield from open(tmp_file) Here's the exception Python 3.6 raises for the above code:
File "example.py", line 4 yield from open(tmp_file) ^ SyntaxError: 'yield from' inside async function