Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion with-statement syntactic quirk
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mathias Panzenböck  
View profile  
 More options Oct 31 2012, 10:47 pm
From: Mathias Panzenböck <grosser.meister.mo...@gmx.net>
Date: Thu, 01 Nov 2012 03:46:36 +0100
Local: Wed, Oct 31 2012 10:46 pm
Subject: Re: [Python-ideas] with-statement syntactic quirk
On 10/31/2012 10:03 PM, Arnaud Delobelle wrote:

> On 31 October 2012 10:38, Barry Warsaw <ba...@python.org> wrote:
>> with-statements have a syntactic quirk, which I think would be useful to fix.
>> This is true in Python 2.7 through 3.3, but it's likely not fixable until 3.4,
>> unless of course it's a bug <wink>.

>> Legal:

>>>>> with open('/etc/passwd') as p1, open('/etc/passwd') as p2: pass

>> Not legal:

>>>>> with (open('/etc/passwd') as p1, open('/etc/passwd') as p2): pass

>> Why is this useful?  If you need to wrap this onto multiple lines, say to fit
>> it within line length limits.  IWBNI you could write it like this:

>>      with (open('/etc/passwd') as p1,
>>            open('/etc/passwd') as p2):
>>            pass

>> This seems analogous to using parens to wrap long if-statements, but maybe
>> there's some subtle corner of the grammar that makes this problematic (like
>> 'with' treating the whole thing as a single context manager).

>> Of course, you can wrap with backslashes, but ick!

> No need for backslashes, just put the brackets in the right place:

>      with (
>              open('/etc/passwd')) as p1, (
>              open('/etc/passwd')) as p2:
>         pass

> ;)

Because that's not confusing. Why not write:

        with open('/etc/passwd'
                        ) as p1, open(
                        '/etc/passwd') as p2:
                pass
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.