On 2019-11-13 18:26, gabriel.ka...@mail.de wrote:
Hello everybody,

today I tried to open four files simultaneously by writing

with (
     open(fname1) as f1,
     open(fname2) as f2,
     open(fname3) as f3,
     open(fname4) as f4
):
     ...

However, this results in a SyntaxError which is caused by the extra brackets. 
Is there a reason that brackets are not allowed in this place?

The syntax (slightly simplified) is:

    "with" expression ["as" name] ":"

but the expression itself can start with a parenthesis, so if it saw a parenthesis after the "with" it would be ambiguous.

For example, compare:

    with (open(fname1) as f1, open(fname2) as f2):

with:

    with (open(fname1)) as f1, open(fname2) as f2:
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/D3MRZXXGSTM4Z5ZDZWCUIB6H56BR76IL/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to