OT: Addition of a .= operator
Simon Ward
simon+python at bleah.co.uk
Fri Jun 9 11:41:42 EDT 2023
On Wed, May 24, 2023 at 05:18:52PM +1200, dn via Python-list wrote:
>>Note that the line numbers correctly show the true cause of the
>>problem, despite both of them being ValueErrors. So if you have to
>>debug this sort of thing, make sure the key parts are on separate
>>lines (even if they're all one expression, as in this example), and
>>then the tracebacks should tell you what you need to know.
>
>
>Yes, an excellent example to show newcomers to make use of 'the
>information *provided*' - take a deep breath and read through it all,
>picking-out the important information...
>
>
>However, returning to "condense this into a single line", the
>frequently-seen coding is (in my experience, at least):
>
> quantity = float( input( "How many would you like? " ) )
>
>which would not produce the helpful distinction between
>line-numbers/function-calls which the above (better-formatted) code
>does!
Old thread I know, but thought it was worth pointing out that Python 3.11
brought in fine-graned error locations in tracebacks[1]:
$ python3.10 asin.py
Enter a small number: 4
Traceback (most recent call last):
File "/home/p10365088/asin.py", line 3, in <module>
print(math.asin(float(input("Enter a small number: "))))
ValueError: math domain error
$ python3.11 asin.py
Enter a small number: 4
Traceback (most recent call last):
File "/home/p10365088/asin.py", line 3, in <module>
print(math.asin(float(input("Enter a small number: "))))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: math domain error
[1]: https://docs.python.org/3/whatsnew/3.11.html#whatsnew311-pep657
Regards,
Simon
--
A complex system that works is invariably found to have evolved from a
simple system that works.—John Gall
More information about the Python-list
mailing list