[Python-ideas] Modern language design survey for "assign and compare" statements
Juancarlo Añez
apalala at gmail.com
Sun May 20 20:55:20 EDT 2018
> > print(child_pid) # child_pid is undefined
>
> Why on earth would it be undefined?
>
Indeed, users would expect the new uses of "as" to behave as the previous
ones. The problem is that "with" and "except" do things differently:
In [*1*]: *import* *os*
In [*2*]: *with* open(os.path.expanduser('~/tmp/xx')) *as* f:
...: *pass*
...:
In [*3*]: print(f)
<_io.TextIOWrapper name='/Users/apalala/tmp/xx' mode='r' encoding='UTF-8'>
In [*4*]: *try*:
...: print('ok')
...: *raise* *Exception*()
...: *except* *Exception* *as* e:
...: *pass*
...:
In [*5*]: print(e)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-5-bb2ea196f768> in <module>()
----> 1 print(e)
NameError: name 'e' is not defined
> Anyway, if you want to propose an alternative to PEP 572, you ought to
> write your own competing PEP.
>
I don't take that as a challenge. It would be good to have different, maybe
somewhat competing PEPs. It's been done before.
--
Juancarlo *Añez*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180520/667ff70e/attachment-0001.html>
More information about the Python-ideas
mailing list