py bug.pyTraceback (most recent call last):
File "C:\Usenet\bug.py", line 5, in <module>
print( a + 12 )
TypeError: can only concatenate str (not "int") to str
Why doesn't Python (error msg) do the obvious thing and tell me
WHAT the actual (offending, arg) values are ?
In many cases, it'd help to know what string the var A had , when the error occurred.
------------ i wouldn't have to put print(a) just above, to see.
( pypy doesn't do that either, but Python makes programming (debugging) so easy that i hardly feel any inconvenience.)
On Wednesday, February 22, 2023 at 12:05:34 PM UTC-8, Hen Hanna wrote:
py bug.pyTraceback (most recent call last):
File "C:\Usenet\bug.py", line 5, in <module>
print( a + 12 )
TypeError: can only concatenate str (not "int") to str
Why doesn't Python (error msg) do the obvious thing and tell me
WHAT the actual (offending, arg) values are ?
In many cases, it'd help to know what string the var A had , when the error occurred.
------------ i wouldn't have to put print(a) just above, to see.
( pypy doesn't do that either, but Python makes programming (debugging) so easy that i hardly feel any inconvenience.)
i see that my example would be clearER with this one-line change:
> py bug.py
Traceback (most recent call last):
File "C:\Usenet\bug.py", line 5, in <module>
map( Func, fooBar( X, Y, X + Y ))
TypeError: can only concatenate str (not "int") to str
i hope that NOW a few of you can see this as a genuine, (reasonable) question.
On Wednesday, February 22, 2023 at 12:05:34 PM UTC-8, Hen Hanna wrote:
py bug.pyTraceback (most recent call last):
File "C:\Usenet\bug.py", line 5, in <module>
print( a + 12 )
TypeError: can only concatenate str (not "int") to str
Why doesn't Python (error msg) do the obvious thing and tell me
WHAT the actual (offending, arg) values are ?
In many cases, it'd help to know what string the var A had , when the error occurred.
------------ i wouldn't have to put print(a) just above, to see.
( pypy doesn't do that either, but Python makes programming (debugging) so easy that i hardly feel any inconvenience.)
i hope that NOW a few of you can see this as a genuine, (reasonable) question.
On 23 Feb 2023, at 01:39, Hen Hanna <henhanna@gmail.com> wrote:
On Wednesday, February 22, 2023 at 3:46:21 PM UTC-8, Hen Hanna wrote:
On Wednesday, February 22, 2023 at 12:05:34 PM UTC-8, Hen Hanna wrote:
py bug.pyTraceback (most recent call last):
File "C:\Usenet\bug.py", line 5, in <module>
print( a + 12 )
TypeError: can only concatenate str (not "int") to str
Why doesn't Python (error msg) do the obvious thing and tell me
WHAT the actual (offending, arg) values are ?
In many cases, it'd help to know what string the var A had , when the error occurred.
------------ i wouldn't have to put print(a) just above, to see.
( pypy doesn't do that either, but Python makes programming (debugging) so easy that i hardly feel any inconvenience.)
i see that my example would be (even) clearER with this one-line change:
py bug.py
Traceback (most recent call last):
File "C:\Usenet\bug.py", line 5, in <module>
map( Func, fooBar( X, Y, X + Y ))
TypeError: can only concatenate str (not "int") to str
attempt to call + with 'abc' , 123.45 <--------------
i hope that NOW a few of you can see this as a genuine, (reasonable) question.
Python seems so perfectly User-friendly that
i 'm so curious (puzzled) that it doesn't do the very obvious and easy thing
of giving me this info:
attempt to call + with 'abc' , 123.45 <--------------
--
https://mail.python.org/mailman/listinfo/python-list
On 23 Feb 2023, at 01:39, Hen Hanna <henh...@gmail.com> wrote:
On Wednesday, February 22, 2023 at 3:46:21 PM UTC-8, Hen Hanna wrote:
On Wednesday, February 22, 2023 at 12:05:34 PM UTC-8, Hen Hanna wrote: >>>> py bug.py
Traceback (most recent call last):
File "C:\Usenet\bug.py", line 5, in <module>
print( a + 12 )
TypeError: can only concatenate str (not "int") to str
Why doesn't Python (error msg) do the obvious thing and tell me
WHAT the actual (offending, arg) values are ?
In many cases, it'd help to know what string the var A had , when the error occurred.
------------ i wouldn't have to put print(a) just above, to see.
( pypy doesn't do that either, but Python makes programming (debugging) so easy that i hardly feel any inconvenience.)
i see that my example would be (even) clearER with this one-line change:
py bug.py
Traceback (most recent call last):
File "C:\Usenet\bug.py", line 5, in <module>
map( Func, fooBar( X, Y, X + Y ))
TypeError: can only concatenate str (not "int") to str
attempt to call + with 'abc', 123 <--------------
i hope that NOW a few of you can see this as a genuine, (reasonable) question.
Python seems so perfectly User-friendly that
i 'm so curious (puzzled) that it doesn't do the very obvious and easy thing
of giving me this info:
attempt to call + with 'abc', 123 <--------------
It is not easy to do that in a robust and reliable way for any object.
You can end up in the code to generate the error message itself breaking. For example using unbounded CPU time when attempting to get the string repr of the variable.
Barry
Python makes programming (debugging) so easyI agree with that!
Python makes programming (debugging) so easyI agree with that!
> py bug.py
Traceback (most recent call last):
File "C:\Usenet\bug.py", line 5, in <module>
print( a + 12 )
TypeError: can only concatenate str (not "int") to str
Why doesn't Python (error msg) do the obvious thing and tell me
WHAT the actual (offending, arg) values are ?
In many cases, it'd help to know what string the var A had , when the error occurred.
------------ i wouldn't have to put print(a) just above, to see.
Python VM is seeing an "int" object (123) (and telling me that) ... so it should be easy to print that "int" objectIt knows there is an object and its name and type. It knows this from
What does Python VM know ? and when does it know it ?
it seems like it is being playful, teasing (or mean), and hiding the ball from me
Python VM is seeing an "int" object (123) (and telling me that) ...so it should be easy to print that "int" object
What does Python VM know ? and when does it know it ?It knows there is an object and its name and type. It knows this from the first moment you create the object and bind a name to it.
it seems like it is being playful, teasing (or mean), and hidingthe ball from me
On Wednesday, February 22, 2023 at 12:05:34 PM UTC-8, Hen Hanna wrote:
py bug.pyTraceback (most recent call last):
File "C:\Usenet\bug.py", line 5, in <module>
print( a + 12 )
TypeError: can only concatenate str (not "int") to str
Why doesn't Python (error msg) do the obvious thing and tell me
WHAT the actual (offending, arg) values are ?
In many cases, it'd help to know what string the var A had , when the error occurred.
------------ i wouldn't have to put print(a) just above, to see.
( pypy doesn't do that either, but Python makes programming
(debugging) so easy that i hardly feel any inconvenience.)
i see that my example would be clearER with this one-line change:
> py bug.py
Traceback (most recent call last):
File "C:\Usenet\bug.py", line 5, in <module>
map( Func, fooBar( X, Y, X + Y ))
TypeError: can only concatenate str (not "int") to str
i hope that NOW a few of you can see this as a genuine, (reasonable) question.
On 2/23/23 01:08, Hen Hanna wrote:
Python VM is seeing an "int" object (123) (and telling me that)It knows there is an object and its name and type. It knows this from
... so it should be easy to print that "int" object What does
Python VM know ? and when does it know it ?
the first moment you create the object and bind a name to it.
it seems like it is being playful, teasing (or mean), and
hiding the ball from me
Sorry you aren't understanding. Whenever you print() out an object,
python calls the object's __repr__() method to generate the string to display. For built-in objects this is obviously trivial. But if you
were dealing an object of some arbitrary class, there may not be a
__repr__() method
which would cause an exception, or if the __repr__()
method itself raised an exception,
In some ways, providing this information seems appropriate. Curiously, this does not even occur during an assert exception - despite the value/relationship being the whole point of using the command!
x = 1
assert x == 2
AssertionError (and that's it)
assert len(a) == len(b)E AssertionError: assert 3 == 2
That said, have observed coders 'graduating' from other languages, making wider use of assert - assumed to be more data (value) sanity-checks than typing, but ...
Do you use assert frequently?
On 2023-02-24 16:12:10 +1300, dn via Python-list wrote:
In some ways, providing this information seems appropriate. Curiously, this >> does not even occur during an assert exception - despite the
value/relationship being the whole point of using the command!
x = 1
assert x == 2
AssertionError (and that's it)
Pytest is great there. If an assertion in a test case fails it analyzes
the expression to give you various levels of details:
======================================== test session starts ========================================
platform linux -- Python 3.10.6, pytest-6.2.5, py-1.10.0, pluggy-0.13.0 rootdir: /home/hjp/tmp/t
plugins: cov-3.0.0, anyio-3.6.1
collected 1 item
test_a.py F [100%]
============================================= FAILURES ==============================================
______________________________________________ test_a _______________________________________________
def test_a():
a = [1, 2, 3]
b = {"a": a, "b": 2}
assert len(a) == len(b)E AssertionError: assert 3 == 2
E + where 3 = len([1, 2, 3])
E + and 2 = len({'a': [1, 2, 3], 'b': 2})
test_a.py:7: AssertionError
====================================== short test summary info ======================================
FAILED test_a.py::test_a - AssertionError: assert 3 == 2 ========================================= 1 failed in 0.09s =========================================
On 25/02/2023 08.12, Peter J. Holzer wrote:
On 2023-02-24 16:12:10 +1300, dn via Python-list wrote:
In some ways, providing this information seems appropriate.
Curiously, this
does not even occur during an assert exception - despite the
value/relationship being the whole point of using the command!
    x = 1
    assert x == 2
AssertionError (and that's it)
Traceback (most recent call last):a = [1,2,3]
b = [4,5]
assert len(a) == len(b), f'len(a): {len(a)} != len(b): {len(b)}'
Traceback (most recent call last):c = {"a": a, "b": 2}
assert a > c
Pytest is great there. If an assertion in a test case fails it analyzes
the expression to give you various levels of details:
======================================== test session starts
========================================
platform linux -- Python 3.10.6, pytest-6.2.5, py-1.10.0, pluggy-0.13.0
rootdir: /home/hjp/tmp/t
plugins: cov-3.0.0, anyio-3.6.1
collected 1 item
test_a.py
FÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â [100%]
============================================= FAILURES
==============================================
______________________________________________ test_a
_______________________________________________
    def test_a():
        a = [1, 2, 3]
        b = {"a": a, "b": 2}
      assert len(a) == len(b)E      AssertionError: assert 3 == 2
EÂ Â Â Â Â Â Â +Â where 3 = len([1, 2, 3])
E       + and  2 = len({'a': [1, 2, 3], 'b': 2})
test_a.py:7: AssertionError
====================================== short test summary info
======================================
FAILED test_a.py::test_a - AssertionError: assert 3 == 2
========================================= 1 failed in 0.09s
=========================================
+1
and hence the tone of slight surprise in the observation - because only
ever use assert within pytests, and as observed, pytest amplifies the report-back to provide actionable-intelligence. See also: earlier contribution about using a debugger.
That said, have observed coders 'graduating' from other languages,
making wider use of assert - assumed to be more data (value)
sanity-checks than typing, but ...
Do you use assert frequently?
The OP seems wedded to his?her ways, complaining that Python does not
work the way it 'should'. In turn, gives rise to the impression that expounding the advantages of TDD, and thus anticipating such unit and integration error-possibilities, might be considered an insult or
unhelpful.
(sigh!)
Personally, I struggled a bit to adapt from the more-strictured (if not more-structured) languages of my past, to Python - particularly the
different philosophies or emphases of what happens at 'compile-time' cf 'execution-time'; and how such required marked changes in attitudes to design, time-allocation, work-flow, and tool-set. Two related-activities which made the language-change more workable and unleashed greater than step-change advantage, were: increased use of TDD, and actively learning
the facilities within Python-oriented IDEs.
On 2/24/2023 2:47 PM, dn via Python-list wrote:
On 25/02/2023 08.12, Peter J. Holzer wrote:
On 2023-02-24 16:12:10 +1300, dn via Python-list wrote:
In some ways, providing this information seems appropriate.
Curiously, this does not even occur during an assert exception - despite the value/relationship being the whole point of using
the command!
x = 1
assert x == 2
AssertionError (and that's it)
Sometimes you can use a second parameter to assert if you know what kind of error to expect:
File "<stdin>", line 1, in <module>a = [1,2,3]
b = [4,5]
assert len(a) == len(b), f'len(a): {len(a)} != len(b): {len(b)}' Traceback (most recent call last):
AssertionError: len(a): 3 != len(b): 2
With type errors, assert may actually give you the information needed:
Traceback (most recent call last):c = {"a": a, "b": 2}
assert a > c
File "<stdin>", line 1, in <module>
TypeError: '>' not supported between instances of 'list' and 'dict'
On 2023-02-24 18:19:52 -0500, Thomas Passin wrote:
On 2/24/2023 2:47 PM, dn via Python-list wrote:
On 25/02/2023 08.12, Peter J. Holzer wrote:
On 2023-02-24 16:12:10 +1300, dn via Python-list wrote:
In some ways, providing this information seems appropriate.
Curiously, this does not even occur during an assert exception -
despite the value/relationship being the whole point of using
the command!
    x = 1
    assert x == 2
AssertionError (and that's it)
Sometimes you can use a second parameter to assert if you know what kind of >> error to expect:
Traceback (most recent call last):a = [1,2,3]
b = [4,5]
assert len(a) == len(b), f'len(a): {len(a)} != len(b): {len(b)}'
File "<stdin>", line 1, in <module>
AssertionError: len(a): 3 != len(b): 2
Yup. That's very useful (but I tend to forget that).
With type errors, assert may actually give you the information needed:
Traceback (most recent call last):c = {"a": a, "b": 2}
assert a > c
File "<stdin>", line 1, in <module>
TypeError: '>' not supported between instances of 'list' and 'dict'
Actually in this case it isn't assert which gives you the information,
it's evaluating the expression itself. You get the same error with just
a > c
on a line by its own.
On 2/25/2023 1:13 AM, Peter J. Holzer wrote:[...]
On 2023-02-24 18:19:52 -0500, Thomas Passin wrote:
Sometimes you can use a second parameter to assert if you know what kind of
error to expect:
With type errors, assert may actually give you the information needed:
Traceback (most recent call last):c = {"a": a, "b": 2}
assert a > c
File "<stdin>", line 1, in <module>
TypeError: '>' not supported between instances of 'list' and 'dict'
Actually in this case it isn't assert which gives you the information,
it's evaluating the expression itself. You get the same error with just
a > c
on a line by its own.
In some cases. For my example with an explanatory string, you wouldn't want to write code like that after an ordinary line of code, at least not very often. The assert statement allows it syntactically.
On 2/25/2023 1:13 AM, Peter J. Holzer wrote:[...]
On 2023-02-24 18:19:52 -0500, Thomas Passin wrote:
Sometimes you can use a second parameter to assert if you know what kind of
error to expect:
With type errors, assert may actually give you the information needed:
Traceback (most recent call last):c = {"a": a, "b": 2}
assert a > c
File "<stdin>", line 1, in <module>
TypeError: '>' not supported between instances of 'list' and 'dict'
Actually in this case it isn't assert which gives you the information,
it's evaluating the expression itself. You get the same error with just
a > c
on a line by its own.
In some cases. For my example with an explanatory string, you wouldn't want to write code like that after an ordinary line of code, at least not very often. The assert statement allows it syntactically.
For that use, the default behavior –telling me which line the assert
is on, is more than sufficient. Depending on the circumstance, I’ll
re-run the code with a breakpoint or replace the assert with an
informative f-string Exception.
I only use asserts for things I know to be true.
In other words, a failing assert means I have a hole in my program
logic.
For that use, the default behavior –telling me which line the assert
is on, is more than sufficient. Depending on the circumstance, I’ll
re-run the code with a breakpoint or replace the assert with an
informative f-string Exception.
I only use asserts for things I know to be true.
In other words, a failing assert means I have a hole in my program
logic.
For that use, the default behavior –telling me which line the assert
is on, is more than sufficient. Depending on the circumstance, I’ll
re-run the code with a breakpoint or replace the assert with an
informative f-string Exception.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 78:07:38 |
Calls: | 6,716 |
Files: | 12,247 |
Messages: | 5,357,827 |