I don't have enough experience to compare with anything, ** Python error messages are concrete and easy to understand ** I feel that. Therefore, the error is not only a quick glance, To read the contents seriously I feel that it is a shortcut for error resolution.
This is an article to show such feelings.
... AAA yyy BBB The supplementary ** ... AAA yyy BBB ** means that the order of the elements that cause the error is displayed seriously. I wrote it in the sense that it will be done.
As I will show later, simply
TypeError: unsupported operand type(s) for *: 'generator' and 'float'
It refers to the display like (the latter half).
The code shown here is for issuing an error message. It's not code that can make exactly the same mistakes. I repeat. This is the code to issue an error message. (However, I've seen the same error in a slightly more confusing code.)
This is the case where you get a type error ** TypeError **.
The code is below.
gen_erro1.py
def my_range(first=0, last=10, step=1):
number = first
while number < last:
yield number
number += step
ranger = my_range(1, 5)
ranger2 = ranger * 2.0 #<--Incomprehensible code to give an error
for x in ranger:
print(x)
The error display is as follows.
C:\_temp_work\error1>python gen_error1.py
Traceback (most recent call last):
File "gen_error1.py", line 7, in <module>
ranger2 = ranger * 2.0
TypeError: unsupported operand type(s) for *: 'generator' and 'float'
... AAA yyy BBB In that sense To'generator'and'float' I tried to make * work You can see that it is not supported **. ** ** For a little more complicated code, **'generator' When 'float' With the information that they are calling in this order ** You'll probably notice in a short amount of time what's wrong (such as what's disappointing).
This is the case where you get a type error ** TypeError **.
The code is below.
gen_error2.py
def my_range(first=0, last=10, step=1):
number = first
while number < last:
yield number
number += step
ranger = my_range(1, 5)
ranger2 = 2.0 * ranger #<--Incomprehensible code to give an error
for x in ranger:
print(x)
The content of the error is as follows.
C:\_temp_work\error1>python gen_error2.py
Traceback (most recent call last):
File "gen_error2.py", line 7, in <module>
ranger2 = 2.0 * ranger
TypeError: unsupported operand type(s) for *: 'float' and 'generator'
C:\_temp_work\error1>
... AAA yyy BBB In that sense To'float'and'generator' I tried to make * work You can see that it is not supported **. ** ** **'float' When 'generator' With the information that they are calling in this order ** You'll probably notice in a short amount of time what's wrong (such as what's disappointing).
I think it's a natural result in terms of composing the error message, but I felt it was easy to understand. .. ..
Use python without stress! (Become familiar with generator. It seems to be since1975.)
Use python without stress! (In Python, everything is implemented as an object) Use python without stress! (Close to Pylint) Use python without stress! (Expression and Statement) Learn Python carefully using both English and Japanese.
If you have any comments, please let us know. : candy: Will study,,,,
Recommended Posts