In this post , we will see & Fix - Common Python Errors. Python is one of the most widely adopted language now. It is interesting to learn & there are plenty of application opportunities for it - be it Data Science, Data Analytics, Automation, Scripting, Web Backend etc. So we will explore the various Python Errors that we face day to day and their fixes and solutions in a short and succinct manner.
>>> '1'+1 -----> char + num
It means you are trying to apply an operation or a function to something you shouldn't i.e. to something of inappropriate type. In this case , doing addition between a "string" type and a Number !
>>> from x import test
>>> import test
ImportError: cannot import name 'test'
assert_stmt ::= "assert" expression ["," expression]
if __debug__:
if not expression: raise AssertionError
import A
matrix = A.aa(<some_arguments>)
AttributeError: 'A' object has no attribute 'aa'
$ python -c 'input()' < /dev/null
Traceback (most recent call last):
File "<string>", line 1, in <module>
EOFError: EOF when reading a line
except EOFError:
print('Caught EOFError')
break
import numpy as np
>>> with np.errstate(invalid='raise'):
... np.sqrt(-1)
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
FloatingPointError: invalid value encountered in sqrt
Hope this helps.
Other Good Reads -
python error,attributeerror , FloatingPointError , EOFError , AssertionError , ImportError , TypeError