Python – list of bugs and their fixes

List of common mistakes in Python and their fixes.

TypeError: object is not subscriptable

An error that says that accessing elements is not correct. It may be a different type of object than what you think. You can check with the command type ()

For example, this could be if it is list, and in referring to the element to dictionary

TypeError: unsupported type for timedelta days component: str

A number is expected, and a string is passed in timedelta. The fix is ​​simple, if you are sure that a digit is being transmitted, then it is enough to explicitly convert to a number: int (days)

Failed execute: tuple index out of range

Means that less data is transmitted than requested.

ModuleNotFoundError: No module named ‘bot.bot_handler’; ‘bot’ is not a package

venv / bin / python bot / bot.py
Traceback (most recent call last):
File “bot / bot.py”, line 4, in
from bot.bot_handler import BotHandler
File “bot / bot.py”, line 4, in
from bot.bot_handler import BotHandler
ModuleNotFoundError: No module named ‘bot.bot_handler’; ‘bot’ is not a package

Filename and directory name confusion – they shouldn’t be the same here. Change the directory name or file name.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *