[Python-ideas] Null coalescing operators
Matthias Bussonnier
bussonniermatthias at gmail.com
Tue Sep 22 04:00:26 CEST 2015
Hi Chris,
On Mon, Sep 21, 2015 at 5:44 PM, Chris Angelico <rosuav at gmail.com> wrote:
>
> Are there any uses like this that would involve a question mark
> followed by some other punctuation? The main proposal would be for
> x?.y and similar; if "x ?? y" can't be used because of a conflict with
> ipython,
As far as I can tell, no `?`/`??` behave in IPython like a unary
operator[1] and don't conflict.
We could distinguish from any use case so far mentioned in this discussion
(as far as I can tell). I just hope that the PEP will not slide in the
direction of
`foo?` alone being valid and equivalent to `maybe(x)`, or returning an object.
I'm concern about teaching/semantics as for me `x?.y` read like "The
attribute y of the help of x"
so roughly `help(x).y`. The `x ?? y` is less ambiguous (imho) as it is
clearly an operator
with the space on each side.
> I'm sure it could be changed ("x ?! y" would be cute).
Is that the WTF operator ? [2]
Joke aside, ?! should not conflict either, but `!` and `!!` also have
their own meaning in IPython
Like the following is valid (which is a useless piece of code, but to
show the principles)
if you are interested in the Python syntax extension we have.
my_files = ! ls ~/*.txt
for i,file in enumerate(my_files):
raw = !cat $file
!cat $raw > {'%s-%s'%(i,file.upper())}
Thanks,
--
M
[1]: but is not really an operator, I'm not sure what a=print? ; a
=?print or ?a=print would do.
[2]: http://stackoverflow.com/questions/7825055/what-does-the-c-operator-do
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
More information about the Python-ideas
mailing list