On Wed, Oct 21, 2020 at 03:19:20AM +1100, Chris Angelico wrote:

> In every sscanf-like system I've used, there is a default value of
> some sort, either because variables are automatically initialized, or
> because the sscanf construct itself provides a default.

Then it won't go "Boom!" as you said. It will just return the default.

So your boom objection is neutralised, yay!


> You can always
> explicitly initialize them if you need to:
> 
> spam = eggs = cheese = None
> f"{spam:d} {eggs:d} {cheese:d}" = "123 456"
> 
> Oh look, not nearly as ugly as your strawman :)

You still have to test for None. Perhaps not as awkward as try...except, 
but you still have to test each one.

Hey, it's past my bed time. I didn't think of that. But I did think of 
this:

    # Check whether the pattern was matched and bound to a variable.
    if 'spam' in locals():
        if 'eggs' in locals():
            # etc


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/6HRVAZ42UCNQ5ECSSKTTSJNGG3NGKTSW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to