<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<font face="monospace, monospace">
<blockquote type="cite">For instance, what would the following do?<br>
<br>
<font face="monospace, monospace">initial = <a
href="http://person.name">person.name</a>[0] with
suppress(AttributeError) # Hangover from PEP 505
discussion...</font></blockquote>
</font>As the with-expression mimics the with-statement I would say
this is similar to:<br>
<pre>with supress(AttributeError):
tmp = person.name[0]
initial = tmp # Error on assignment wouldn't get suppressed. Not relevant for this case but still.
</pre>
I don't understand where this is ambigous?<br>
<br>
<blockquote type="cite"
cite="mid:CAKr=oZs2qgG-cBZ_Dk1+NJx3TpXS1aKw0AU-YuetoxAoYDiVBQ@mail.gmail.com">
<div dir="ltr">So maybe it only makes sense to use expression
assignment (PEP 572):<br>
<div>
<div><br>
data = (d := file.read() with open(...) as file)<br>
<br>
To which I say, "Eww..."<br>
</div>
</div>
</div>
</blockquote>
I definitely agree that this looks a bit bad but I don't get why you
would consider using an expression assignment there.<br>
<pre>data = file.read with open(...) as file</pre>
works perfectly fine so why would you want to additonaly assign it
to another variable "d"?<br>
<br>
<br>
Overall I like the idea of the with-expression as it allows you to
make some common use cases like the open/read example more readable.
It's clear at first sight that what is actually done is reading the
file. While it's true that it's usually easy to write a simple
function to do the job that still isn't as simple to understand and
in most cases when reading the code you then have to look at the
function to see if anything else is done there. Also what if you
then do readlines somewhere? Then you need another function.<br>
</body>
</html>