On 17 August 2014 07:42, Chris Angelico wrote:
> On Sat, Aug 16, 2014 at 10:47 PM, Marko Rauhamaa wrote:
>>
>> You might be able to have it bothways. You could have:
>>
>>with (open(name) for name in os.listdir("config")) as files:
>
> But that's not a tuple, it's a generator. Should generato
On Sat, Aug 16, 2014 at 10:47 PM, Marko Rauhamaa wrote:
>
> You might be able to have it bothways. You could have:
>
>with (open(name) for name in os.listdir("config")) as files:
But that's not a tuple, it's a generator. Should generators be context
managers? Is anyone seriously suggesting th
Steven D'Aprano :
> I simply don't care. They will try it, discover that tuples are not
> context managers, fix their code, and move on.
*Could* tuples (and lists and sequences) be context managers?
*Should* tuples (and lists and sequences) be context managers?
> I don't think that some vague
On Sat, Aug 16, 2014 at 05:25:33PM +1000, Ben Finney wrote:
[...]
> > they would have already mistaken:
> >
> > with a, b, c: ...
> >
> > the same way. But they haven't.
>
> Right. The presence or absence of parens make a big semantic difference.
from silly.mistakes.programmers.make import (
On Sat, Aug 16, 2014 at 12:25 AM, Ben Finney wrote:
> Steven D'Aprano writes:
>
>> If people were going to be prone to mistake
>>
>> with (a, b, c): ...
>>
>> as including a tuple
>
> … because the parens are a strong signal “this is an expression to be
> evaluated, resulting in a single valu
Steven D'Aprano writes:
> If people were going to be prone to mistake
>
> with (a, b, c): ...
>
> as including a tuple
… because the parens are a strong signal “this is an expression to be
evaluated, resulting in a single value to use in the statement”.
> they would have already mistaken:
>
On Fri, Aug 15, 2014 at 08:29:09PM -0700, Ethan Furman wrote:
> On 08/15/2014 08:08 PM, Steven D'Aprano wrote:
[...]
> >is a poor argument (that is, I'm disagreeing with it), since *single*
> >line parens-free with statements are already syntactically a tuple:
> >
> > with spam, eggs, cheese:
On 08/15/2014 08:08 PM, Steven D'Aprano wrote:
On Fri, Aug 15, 2014 at 02:08:42PM -0700, Ethan Furman wrote:
On 08/13/2014 10:32 AM, Steven D'Aprano wrote:
(2) Also note that *this is already the case*, since tuples are made by
the commas, not the parentheses. E.g. this succeeds:
# Not a tupl
On Fri, Aug 15, 2014 at 02:08:42PM -0700, Ethan Furman wrote:
> On 08/13/2014 10:32 AM, Steven D'Aprano wrote:
> >
> >(2) Also note that *this is already the case*, since tuples are made by
> >the commas, not the parentheses. E.g. this succeeds:
> >
> ># Not a tuple, actually two context managers.
On 08/15/2014 11:08 PM, Ethan Furman wrote:
> On 08/13/2014 10:32 AM, Steven D'Aprano wrote:
>>
>> (2) Also note that *this is already the case*, since tuples are made by
>> the commas, not the parentheses. E.g. this succeeds:
>>
>> # Not a tuple, actually two context managers.
>> with open("/tmp/f
On 08/13/2014 10:32 AM, Steven D'Aprano wrote:
(2) Also note that *this is already the case*, since tuples are made by
the commas, not the parentheses. E.g. this succeeds:
# Not a tuple, actually two context managers.
with open("/tmp/foo"), open("/tmp/bar", "w"):
pass
Thanks for proving m
On 08/12/2014 08:38 PM, Steven D'Aprano wrote:
[1] Technically not, since it's the comma, not the ( ), which makes a
tuple, but a lot of people don't know that and treat it as if it the
parens were compulsary.
It might as well be, because if there can be a non-tuple way to interpret the comma
On Wed, Aug 13, 2014 at 08:08:51PM +0300, yoav glazner wrote:
[...]
> Just a thought, would it bit wierd that:
> with (a as b, c as d): "works"
> with (a, c): "boom"
> with(a as b, c): ?
If this proposal is accepted, there is no need for the "boom". The
syntax should allow:
# Without parens, lim
On Aug 13, 2014 7:04 PM, "Akira Li" <4kir4...@gmail.com> wrote:
>
> Nick Coghlan writes:
>
> > On 12 August 2014 22:15, Steven D'Aprano wrote:
> >> Compare the natural way of writing this:
> >>
> >> with open("spam") as spam, open("eggs", "w") as eggs,
frobulate("cheese") as cheese:
> >> # do
Nick Coghlan writes:
> On 12 August 2014 22:15, Steven D'Aprano wrote:
>> Compare the natural way of writing this:
>>
>> with open("spam") as spam, open("eggs", "w") as eggs, frobulate("cheese") as
>> cheese:
>> # do stuff with spam, eggs, cheese
>>
>> versus the dynamic way:
>>
>> with Exi
On 12 August 2014 22:15, Steven D'Aprano wrote:
> Compare the natural way of writing this:
>
> with open("spam") as spam, open("eggs", "w") as eggs, frobulate("cheese") as
> cheese:
> # do stuff with spam, eggs, cheese
>
> versus the dynamic way:
>
> with ExitStack() as stack:
> spam, egg
On Tue, Aug 12, 2014 at 08:04:35AM -0500, Ian Cordasco wrote:
> I think by introducing parentheses we are going to risk seriously
> confusing users who may then try to write an assignment like
>
> a = (open('spam') as spam, open('eggs') as eggs)
Seriously?
If they try it, they will get a syntax
On Tue, Aug 12, 2014 at 8:12 AM, Guido van Rossum wrote:
> On Tue, Aug 12, 2014 at 3:43 AM, Devin Jeanpierre
> wrote:
>> The parentheses seem unnecessary/redundant/weird. Why not allow
>> newlines in-between "with" and the terminating ":"?
>>
>> with open('foo') as foo,
>>open('bar') as b
On 08/12/2014 06:57 PM, Armin Rigo wrote:
> Hi,
>
> On 12 August 2014 01:08, Allen Li wrote:
>> with (open('foo') as foo,
>> open('bar') as bar,
>> open('baz') as baz,
>> open('spam') as spam,
>> open('eggs') as eggs):
>> pass
>
> +1. It's exa
Hi,
On 12 August 2014 01:08, Allen Li wrote:
> with (open('foo') as foo,
> open('bar') as bar,
> open('baz') as baz,
> open('spam') as spam,
> open('eggs') as eggs):
> pass
+1. It's exactly the same grammar extension as for "from import"
state
On Tue, Aug 12, 2014 at 3:43 AM, Devin Jeanpierre
wrote:
> I think this thread is probably Python-Ideas territory...
>
> On Mon, Aug 11, 2014 at 4:08 PM, Allen Li wrote:
> > Currently, this works with explicit line continuation, but as all style
> > guides favor implicit line continuation over e
On Tue, Aug 12, 2014 at 7:15 AM, Steven D'Aprano wrote:
> On Tue, Aug 12, 2014 at 10:28:14AM +1000, Nick Coghlan wrote:
>> On 12 Aug 2014 09:09, "Allen Li" wrote:
>> >
>> > This is a problem I sometimes run into when working with a lot of files
>> > simultaneously, where I need three or more `wit
On Tue, Aug 12, 2014 at 10:28:14AM +1000, Nick Coghlan wrote:
> On 12 Aug 2014 09:09, "Allen Li" wrote:
> >
> > This is a problem I sometimes run into when working with a lot of files
> > simultaneously, where I need three or more `with` statements:
> >
> > with open('foo') as foo:
> >
I think this thread is probably Python-Ideas territory...
On Mon, Aug 11, 2014 at 4:08 PM, Allen Li wrote:
> Currently, this works with explicit line continuation, but as all style
> guides favor implicit line continuation over explicit, it would be nice
> if you could do the following:
>
> w
Ben Hoyt writes:
> So -- although I'm not arguing for it here -- you'd be turning an code
> (a runtime AttributeError) into valid syntax.
Exactly what I'd want to avoid, especially because it *looks* like a
tuple. There are IMO too many pieces of code that look confusingly
similar to tuples but
> Even if it weren't a syntax error, the syntax would be ambiguous. How
> will you discern the meaning of::
>
> with (
> foo,
> bar,
> baz):
> pass
>
> Is that three separate context managers? Or is it one tuple with three
> items?
Is it meaningful t
On 12 Aug 2014 09:09, "Allen Li" wrote:
>
> This is a problem I sometimes run into when working with a lot of files
> simultaneously, where I need three or more `with` statements:
>
> with open('foo') as foo:
> with open('bar') as bar:
> with open('baz') as baz:
>
Allen Li writes:
> Currently, this works with explicit line continuation, but as all
> style guides favor implicit line continuation over explicit, it would
> be nice if you could do the following:
>
> with (open('foo') as foo,
> open('bar') as bar,
> open('baz') as baz,
>
This is a problem I sometimes run into when working with a lot of files
simultaneously, where I need three or more `with` statements:
with open('foo') as foo:
with open('bar') as bar:
with open('baz') as baz:
pass
Thankfully, support for multiple items was
29 matches
Mail list logo