<div dir="ltr"><br><br>On Monday, July 30, 2018 at 3:55:25 PM UTC-4, Kyle Lahnakoski wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Rudy,<p>I think your proposal may be very specific to iterable context managers;<br></p></blockquote><div><br></div><div>I don't think his proposal is specific to iterable context managers.  You can have a with clause that is used in a following for clause. </div><div><br></div><blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><p>in which case, make a method that makes that assumption:</p><p>> def iter_with(obj):<br>>     with obj as context:<br>>         yield from context</p><p>and use it</p><p>> g = (<br>>     f.read()<br>>     for fn in filenames<br>>     for f in iter_with(open(fn))<br>> )</p><p>On 2018-07-30 15:15, Rudy Matela wrote:<br>> Hello,<br>><br>> Do you think it would be nice to allow with statements inside genexps or<br>> list comprehensions?  The functions __enter__ and __exit__ would be<br>> automatically called as iterables are traversed.  I am thinking of<br>> drafting a PEP about this.  Examples:<br>><br>><br>> This <br>><br>>         g = (f.read() for fn in filenames with open(fn) as f)<br>><br>> would be equivalent to the following use of a generator function:<br>><br>>         def __gen():<br>>                 for fn in filenames:<br>>                         with open(fn) as f:<br>>                               <wbr>  yield f.read()<br>>         g = __gen()<br>><br>><br>> This<br>><br>>         list = [f.read() for fn in filenames with open(fn) as f]<br>><br>> would be equivalent to the following:<br>><br>>         list = []<br>>         for fn in filenames:<br>>                 with open(fn) as f:<br>>                         list.<wbr>append(f.read())<br>><br>> --<br>> Rudy<br>> ______________________________<wbr>_________________<br>> Python-ideas mailing list<br>> <a href="javascript:" target="_blank" gdf-obfuscated-mailto="Y4XZCIWiCwAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">Python...@python.org</a><br>> <a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\x3dhttps%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-ideas\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFj1EaNHnVmh20FnFPoUi4J-MpfQw';return true;" onclick="this.href='https://www.google.com/url?q\x3dhttps%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-ideas\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFj1EaNHnVmh20FnFPoUi4J-MpfQw';return true;">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>> Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHJOrArSUDKkjrnthO6_CznMzkPsA';return true;" onclick="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHJOrArSUDKkjrnthO6_CznMzkPsA';return true;">http://python.org/psf/<wbr>codeofconduct/</a></p><p>______________________________<wbr>_________________<br>Python-ideas mailing list<br><a href="javascript:" target="_blank" gdf-obfuscated-mailto="Y4XZCIWiCwAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">Python...@python.org</a><br><a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\x3dhttps%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-ideas\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFj1EaNHnVmh20FnFPoUi4J-MpfQw';return true;" onclick="this.href='https://www.google.com/url?q\x3dhttps%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-ideas\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFj1EaNHnVmh20FnFPoUi4J-MpfQw';return true;">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHJOrArSUDKkjrnthO6_CznMzkPsA';return true;" onclick="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHJOrArSUDKkjrnthO6_CznMzkPsA';return true;">http://python.org/psf/<wbr>codeofconduct/</a><br></p><p></p><p></p><p></p><p></p><p></p></blockquote></div>