<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments for Omar Abo-Namous</title>
	<atom:link href="http://omar.toomuchcookies.net/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://omar.toomuchcookies.net</link>
	<description></description>
	<lastBuildDate>Tue, 10 Jan 2012 00:09:30 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>Comment on Pythonic way of opening more than one file at a time by Tim McNamara</title>
		<link>http://omar.toomuchcookies.net/node/2012/01/pythonic-way-of-opening-more-than-one-file-at-a-time/comment-page-1/#comment-3959</link>
		<dc:creator>Tim McNamara</dc:creator>
		<pubDate>Tue, 10 Jan 2012 00:09:30 +0000</pubDate>
		<guid isPermaLink="false">http://omar.toomuchcookies.net/?p=558#comment-3959</guid>
		<description>This would be more Pythonic if it followed PEP-8 &amp; avoided camelCase.</description>
		<content:encoded><![CDATA[<p>This would be more Pythonic if it followed PEP-8 &amp; avoided camelCase.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Pythonic way of opening more than one file at a time by Nick Coghlan</title>
		<link>http://omar.toomuchcookies.net/node/2012/01/pythonic-way-of-opening-more-than-one-file-at-a-time/comment-page-1/#comment-3941</link>
		<dc:creator>Nick Coghlan</dc:creator>
		<pubDate>Mon, 09 Jan 2012 00:21:56 +0000</pubDate>
		<guid isPermaLink="false">http://omar.toomuchcookies.net/?p=558#comment-3941</guid>
		<description>Nooo, don&#039;t use contextlib.nested(). It&#039;s an error-prone bug trap, and this kind of situation is exactly why it was deprecated in 2.7 and 3.2 and will be gone completely in 3.3. (Quiz: what happens if the first open() call succeeds, but the second one fails?)

I&#039;m the main contextlib maintainer, and contextlib2.ContextStack is a new API I have created and published on PyPI that will hopefully provide the dynamic context management benefits of nested() without being anywhere near as error-prone. The &quot;open a data driven number files at the same time&quot; use case is actually the recurring example I use in the documentation (http://contextlib2.readthedocs.org/en/latest/index.html#contextlib2.ContextStack)</description>
		<content:encoded><![CDATA[<p>Nooo, don&#8217;t use contextlib.nested(). It&#8217;s an error-prone bug trap, and this kind of situation is exactly why it was deprecated in 2.7 and 3.2 and will be gone completely in 3.3. (Quiz: what happens if the first open() call succeeds, but the second one fails?)</p>
<p>I&#8217;m the main contextlib maintainer, and contextlib2.ContextStack is a new API I have created and published on PyPI that will hopefully provide the dynamic context management benefits of nested() without being anywhere near as error-prone. The &#8220;open a data driven number files at the same time&#8221; use case is actually the recurring example I use in the documentation (<a href="http://contextlib2.readthedocs.org/en/latest/index.html#contextlib2.ContextStack" rel="nofollow">http://contextlib2.readthedocs.org/en/latest/index.html#contextlib2.ContextStack</a>)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Pythonic way of opening more than one file at a time by admin</title>
		<link>http://omar.toomuchcookies.net/node/2012/01/pythonic-way-of-opening-more-than-one-file-at-a-time/comment-page-1/#comment-3939</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Sun, 08 Jan 2012 22:30:09 +0000</pubDate>
		<guid isPermaLink="false">http://omar.toomuchcookies.net/?p=558#comment-3939</guid>
		<description>Wow. Thank you guys for the input, i will have to go through the comments slowly.</description>
		<content:encoded><![CDATA[<p>Wow. Thank you guys for the input, i will have to go through the comments slowly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Pythonic way of opening more than one file at a time by Leonhard</title>
		<link>http://omar.toomuchcookies.net/node/2012/01/pythonic-way-of-opening-more-than-one-file-at-a-time/comment-page-1/#comment-3938</link>
		<dc:creator>Leonhard</dc:creator>
		<pubDate>Sun, 08 Jan 2012 21:45:43 +0000</pubDate>
		<guid isPermaLink="false">http://omar.toomuchcookies.net/?p=558#comment-3938</guid>
		<description>In python 2.7 you can open two files in the same with statement.

with open(x) as u, open(y) as w:
    pass</description>
		<content:encoded><![CDATA[<p>In python 2.7 you can open two files in the same with statement.</p>
<p>with open(x) as u, open(y) as w:<br />
    pass</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Pythonic way of opening more than one file at a time by Michael Hunter</title>
		<link>http://omar.toomuchcookies.net/node/2012/01/pythonic-way-of-opening-more-than-one-file-at-a-time/comment-page-1/#comment-3937</link>
		<dc:creator>Michael Hunter</dc:creator>
		<pubDate>Sun, 08 Jan 2012 21:28:07 +0000</pubDate>
		<guid isPermaLink="false">http://omar.toomuchcookies.net/?p=558#comment-3937</guid>
		<description>This seems a long way to go to just (works in 2.7):

with open(&#039;file1&#039;) as f,\
     open(&#039;file2) as g:
     ...</description>
		<content:encoded><![CDATA[<p>This seems a long way to go to just (works in 2.7):</p>
<p>with open(&#8216;file1&#8242;) as f,\<br />
     open(&#8216;file2) as g:<br />
     &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Pythonic way of opening more than one file at a time by joaquin</title>
		<link>http://omar.toomuchcookies.net/node/2012/01/pythonic-way-of-opening-more-than-one-file-at-a-time/comment-page-1/#comment-3936</link>
		<dc:creator>joaquin</dc:creator>
		<pubDate>Sun, 08 Jan 2012 21:24:20 +0000</pubDate>
		<guid isPermaLink="false">http://omar.toomuchcookies.net/?p=558#comment-3936</guid>
		<description>you can also go to python 32 context managers:

with open(&#039;in.txt&#039;) as infile, open(&#039;out.txt&#039;, &#039;w&#039;) as outfile:</description>
		<content:encoded><![CDATA[<p>you can also go to python 32 context managers:</p>
<p>with open(&#8216;in.txt&#8217;) as infile, open(&#8216;out.txt&#8217;, &#8216;w&#8217;) as outfile:</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Pythonic way of opening more than one file at a time by masklinn</title>
		<link>http://omar.toomuchcookies.net/node/2012/01/pythonic-way-of-opening-more-than-one-file-at-a-time/comment-page-1/#comment-3935</link>
		<dc:creator>masklinn</dc:creator>
		<pubDate>Sun, 08 Jan 2012 20:51:53 +0000</pubDate>
		<guid isPermaLink="false">http://omar.toomuchcookies.net/?p=558#comment-3935</guid>
		<description>There are two major issues with your implementation:

1. If an error happens while closing a file, all next files will be left open
2. If opening one of the file fails, all files previously opened will be left open

You should also close the files in the inverse order than the one you opened them in, but that&#039;s a minor issue.

Overall, the original code should be left as-is when using Python 2.5 or 2.6. For Python 2.7-only code or Python 3 code, `with` can be used with multiple managers out of the box:

    with open(path1, &#039;r&#039;) as file1, open(path2, &#039;r&#039;) as file2:
        # stuff.

See examples at the bottom of the &quot;with statement&quot; section: http://docs.python.org/reference/compound_stmts.html#with</description>
		<content:encoded><![CDATA[<p>There are two major issues with your implementation:</p>
<p>1. If an error happens while closing a file, all next files will be left open<br />
2. If opening one of the file fails, all files previously opened will be left open</p>
<p>You should also close the files in the inverse order than the one you opened them in, but that&#8217;s a minor issue.</p>
<p>Overall, the original code should be left as-is when using Python 2.5 or 2.6. For Python 2.7-only code or Python 3 code, `with` can be used with multiple managers out of the box:</p>
<p>    with open(path1, &#8216;r&#8217;) as file1, open(path2, &#8216;r&#8217;) as file2:<br />
        # stuff.</p>
<p>See examples at the bottom of the &#8220;with statement&#8221; section: <a href="http://docs.python.org/reference/compound_stmts.html#with" rel="nofollow">http://docs.python.org/reference/compound_stmts.html#with</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Pythonic way of opening more than one file at a time by Paul Giannaros</title>
		<link>http://omar.toomuchcookies.net/node/2012/01/pythonic-way-of-opening-more-than-one-file-at-a-time/comment-page-1/#comment-3934</link>
		<dc:creator>Paul Giannaros</dc:creator>
		<pubDate>Sun, 08 Jan 2012 20:09:36 +0000</pubDate>
		<guid isPermaLink="false">http://omar.toomuchcookies.net/?p=558#comment-3934</guid>
		<description>I&#039;d prefer more generic behaviour for this so that you could do e.g.:

with opens(&#039;/tmp/foo.py&#039;, (&#039;/tmp/bar.py&#039;, &#039;w&#039;)) as (f1, f2):
	f2.write(f1.read())


Something like the following would do the trick:

import contextlib

@contextlib.contextmanager
def opens(*fnames):
	fs = []
	for x in fnames:
		if not isinstance(x, tuple):
			x = (x, &#039;r&#039;)
		fs.append(open(*x))
	try:
		yield fs
	finally:
		for f in fs:
			f.close()</description>
		<content:encoded><![CDATA[<p>I&#8217;d prefer more generic behaviour for this so that you could do e.g.:</p>
<p>with opens(&#8216;/tmp/foo.py&#8217;, (&#8216;/tmp/bar.py&#8217;, &#8216;w&#8217;)) as (f1, f2):<br />
	f2.write(f1.read())</p>
<p>Something like the following would do the trick:</p>
<p>import contextlib</p>
<p>@contextlib.contextmanager<br />
def opens(*fnames):<br />
	fs = []<br />
	for x in fnames:<br />
		if not isinstance(x, tuple):<br />
			x = (x, &#8216;r&#8217;)<br />
		fs.append(open(*x))<br />
	try:<br />
		yield fs<br />
	finally:<br />
		for f in fs:<br />
			f.close()</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Pythonic way of opening more than one file at a time by fungusakafungus</title>
		<link>http://omar.toomuchcookies.net/node/2012/01/pythonic-way-of-opening-more-than-one-file-at-a-time/comment-page-1/#comment-3932</link>
		<dc:creator>fungusakafungus</dc:creator>
		<pubDate>Sun, 08 Jan 2012 19:24:15 +0000</pubDate>
		<guid isPermaLink="false">http://omar.toomuchcookies.net/?p=558#comment-3932</guid>
		<description>Maybe contextlib.nested could be of use?

[python]
from contextlib import nested
with nested(open(&#039;file1&#039;), open(&#039;file2&#039;)) as (f1, f2):
    f1.readlines()
    f2.readlines()
[/python]</description>
		<content:encoded><![CDATA[<p>Maybe contextlib.nested could be of use?</p>
<p>[python]<br />
from contextlib import nested<br />
with nested(open(&#8216;file1&#8242;), open(&#8216;file2&#8242;)) as (f1, f2):<br />
    f1.readlines()<br />
    f2.readlines()<br />
[/python]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Pythonic way of opening more than one file at a time by qb</title>
		<link>http://omar.toomuchcookies.net/node/2012/01/pythonic-way-of-opening-more-than-one-file-at-a-time/comment-page-1/#comment-3931</link>
		<dc:creator>qb</dc:creator>
		<pubDate>Sun, 08 Jan 2012 18:17:04 +0000</pubDate>
		<guid isPermaLink="false">http://omar.toomuchcookies.net/?p=558#comment-3931</guid>
		<description>python 2.7 and 3.2.

with open(&#039;one.file&#039;) as file_one, open(&#039;second.file&#039;) as file_second:
    print(file_one)
    print(file_second)</description>
		<content:encoded><![CDATA[<p>python 2.7 and 3.2.</p>
<p>with open(&#8216;one.file&#8217;) as file_one, open(&#8216;second.file&#8217;) as file_second:<br />
    print(file_one)<br />
    print(file_second)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

