<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">What about <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">(| val = get_value(x) |)</code> assignment expression which will be <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">True</code> if success, and <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">None</code> if not?</p>
<p style="margin:0px 0px 1.2em!important">So it will be <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">value = f() if (| f = calculate |) else default</code>…The idea is inspired from C’s assignment, but needs some special treatment for anything which is <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">False</code> in boolean context.</p>
<p style="margin:0px 0px 1.2em!important">With kind regards,</p>
<p style="margin:0px 0px 1.2em!important">-gdg </p>
<div title="MDH:PGRpdj48ZGl2PldoYXQgYWJvdXQgYCh8IHZhbCA9IGdldF92YWx1ZSh4KSB8KWAgYXNzaWdubWVu
dCBleHByZXNzaW9uIHdoaWNoIHdpbGwgYmUgYFRydWVgIGlmIAo8c3BhbiBpZD0iZ21haWwtcmVz
dWx0X2JveCIgY2xhc3M9ImdtYWlsLXNob3J0X3RleHQiIGxhbmc9ImVuIj48c3BhbiBjbGFzcz0i
Z21haWwtIj5zdWNjZXNzLCBhbmQgYE5vbmVgIGlmIG5vdD88YnI+PC9zcGFuPjwvc3Bhbj48L2Rp
dj48ZGl2PjxzcGFuIGlkPSJnbWFpbC1yZXN1bHRfYm94IiBjbGFzcz0iZ21haWwtc2hvcnRfdGV4
dCIgbGFuZz0iZW4iPjxzcGFuIGNsYXNzPSJnbWFpbC0iPlNvIGl0IHdpbGwgYmUgCmB2YWx1ZSA9
IGYoKSBpZiAofCBmID0gY2FsY3VsYXRlIHwpIGVsc2UgZGVmYXVsdGAuLi5UaGUgaWRlYSBpcyBp
bnNwaXJlZCBmcm9tIEMncyBhc3NpZ25tZW50LCBidXQgbmVlZHMgc29tZSBzcGVjaWFsIHRyZWF0
bWVudCBmb3IgYW55dGhpbmcgd2hpY2ggaXMgYEZhbHNlYCBpbiBib29sZWFuIGNvbnRleHQuPGJy
Pjwvc3Bhbj48L3NwYW4+PC9kaXY+PGRpdj48c3BhbiBpZD0iZ21haWwtcmVzdWx0X2JveCIgY2xh
c3M9ImdtYWlsLXNob3J0X3RleHQiIGxhbmc9ImVuIj48c3BhbiBjbGFzcz0iZ21haWwtIj48YnI+
PC9zcGFuPjwvc3Bhbj48L2Rpdj48c3BhbiBpZD0iZ21haWwtcmVzdWx0X2JveCIgY2xhc3M9Imdt
YWlsLXNob3J0X3RleHQiIGxhbmc9ImVuIj48c3BhbiBjbGFzcz0iZ21haWwtIj5XaXRoIGtpbmQg
cmVnYXJkcyw8YnI+PC9zcGFuPjwvc3Bhbj48L2Rpdj48c3BhbiBpZD0iZ21haWwtcmVzdWx0X2Jv
eCIgY2xhc3M9ImdtYWlsLXNob3J0X3RleHQiIGxhbmc9ImVuIj48c3BhbiBjbGFzcz0iZ21haWwt
Ij4tZ2RnPC9zcGFuPjwvc3Bhbj4gPGJyPg==" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0"></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-02-16 10:55 GMT+03:00 Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 16 February 2018 at 12:19, <a href="mailto:rymg19@gmail.com">rymg19@gmail.com</a> <<a href="mailto:rymg19@gmail.com">rymg19@gmail.com</a>> wrote:<br>
> I don't know...to me this looks downright ugly and an awkward special case.<br>
> It feels like it combines reading difficulty of inline assignment with the<br>
> awkwardness of a magic word and the ugliness of using ?. Basically, every<br>
> con of the other proposals combined...<br>
<br>
</span>Yeah, it's tricky to find a spelling that looks nice without being<br>
readily confusable with other existing constructs (most notably<br>
keyword arguments).<br>
<br>
The cleanest *looking* idea I've come up with would be to allow<br>
arbitrary embedded assignments to ordinary frame local variables using<br>
the "(expr as name)" construct:<br>
<br>
value = tmp.strip()[4:].upper() if (var1 as tmp) is not None else None<br>
<br>
value = tmp[4:].upper() if (var1 as tmp) is not None else None<br>
<br>
value = tmp if (var1 as tmp) is not None else tmp if (var2 as tmp)<br>
<span class="">is not None else var3<br>
<br>
</span> value = tmp if not math.isnan((var1 as tmp)) else tmp if not<br>
math.isnan((var2 as tmp)) else var3<br>
<br>
value = f() if (calculate as f) is not None else default<br>
<br>
filtered_values = [val for x in keys if (get_value(x) as val) is not None]<br>
<br>
range((calculate_start() as start), start+10)<br>
data[(calculate_start() as start):start+10]<br>
<br>
value if (lower_bound() as min_val) <= value < min_val+tolerance else 0<br>
<br>
print(f"{(get_value() as tmp)!r} is printed in pure ASCII as<br>
{tmp!a} and in Unicode as {tmp}")<br>
<br>
However, while I think that looks nicer in general, we'd still have to<br>
choose between two surprising behaviours:<br>
<br>
* implicitly delete the statement locals after the statement where<br>
they're set (which still overwrites any values previously bound to<br>
those names, similar to what happens with exception clauses)<br>
* skip deleting, which means references to subexpressions may last<br>
longer than expected (and we'd have the problem where embedded<br>
assignments could overwrite existing local variables)<br>
<br>
The interaction with compound statements would also be tricky to<br>
figure out (especially if we went with the "delete after the<br>
statement" behaviour).<br>
<div class="HOEnZb"><div class="h5"><br>
Cheers,<br>
Nick.<br>
<br>
--<br>
Nick Coghlan | <a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a> | Brisbane, Australia<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</div></div></blockquote></div><br></div>