|
|
|
|
|
by glifchits
2913 days ago
|
|
Interesting! I figured the `as` in a `with` statement was handled uniquely, but I learned something new about Python today: x = open('filename')
x.closed # False
with x:
print(x.readline())
x.closed # True
I think you're right. I prefer the `as` variant for readability. |
|
In cases where __enter__() does something different, the assignment expression and the 'as' variable would have different values (the object of the 'with' statement, x, and the result of calling x.__enter__(), respectively).