Creating a calculator

Steven D'Aprano steve at pearwood.info
Fri Jul 1 09:52:45 EDT 2016


On Fri, 1 Jul 2016 10:25 pm, Christopher Reimer wrote:

> For my BASIC interpreter, each line of BASIC is broken this way into
> tokens.
[...]
> By using * to unpack the split line, my program no longer crashes and no
> try/except block is needed to work around the crash. A later line of code
> will test the expression, ignore if empty or run regex if full.

I wish you wouldn't describe this as "crash".

The Python interpreter should never crash. That would be a segmentation
fault, and that is considered to be a very serious bug.

But *raising an exception* is another story. Raising exceptions is not a
crash, it is the interpreter working as expected. This statement:

    line_number, keyword, expr = "20 END".split(' ', 2)

is SUPPOSED to raise an exception, if it didn't, the interpreter would be
broken. To call that a "crash" is horribly misleading.



-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list