4 ms·
They have a list of proposals for syntax, but "as" keyword isn't there. In the last thread I saw, people claimed that it would be confusing in the with-statemen
by ehsankia 8y ago
They have a list of proposals for syntax, but "as" keyword isn't there. In the last thread I saw, people claimed that it would be confusing in the with-statement, but I have a hard time seeing why. In a with statement, the context manager in my eyes is a property of the with-statement, not the as-statement. You're basically doing `with fp = open():`. Does anyone have a good example of why "as" was a bad candidate?
- philfreo 8y ago"as" (and other alternatives) are mentioned in the PEP here: https://www.python.org/dev/peps/pep-0572/#alternative-spellings https://www.python.org/dev/peps/pep-0572/#alternative-spelli...
- mixmastamyk 8y agoThe behavior is built into the "with" statement. It does not do a direct assignment, but assigns to the result of the context manager call. So having two ways to use "as" in the same statement, with different rules, and confusion of which is which is a mess. Except and import have the issue also with different rules. On the other hand additional "as" assignments are not very useful under those statements, so it would not really happen for the most part. A good compromise discussed was to restrict the "as" assignments to the "if" and "while" statements, and perhaps comprehensions, the only areas there were actual use cases. The PEP authors didn't like this compromise, even though many new languages are choosing this design. They pushed ahead despite resistance from all angles. In short, controversial PEPs that reverse twenty-five year old design choices are controversial. Not sure what they were expecting.