Creating echo bot

what is the value " name " used in this program?

why din’t we defined it

i am getting the error to define to define “name

Hello @Tanu_jain , We can configure a new logger by using the getLogger(name) method. The method expects a name for the logger, else it is going to take the root logger’s name. It is always good practice to give it the modular name by using the __name__ variable. This way the configured logger is always going to track the name of the module that creates a log and therefore easier to analyze later. And what is the error related to define name pls explain it a little bit more.
I hope it is clear to you. In case it is clear to you pls mark it as resolve and provide the rating as well as feedback so that we can improve ourselves.
In case there is still some confusion pls let me know, I will surely try to help you out.
Thanks :slight_smile:
Happy Coding !!

ERROR:Traceback (most recent call last): File “E:\Practice\telegrambot.py”, line 18, in logger = logging.getLogger(name) NameError: name ‘name’ is not definedTraceback (most recent call last): File “E:\Practice\telegrambot.py”, line 18, in logger = logging.getLogger(name) NameError: name ‘name’ is not defined

MY CODE:import logging from telegram.ext import Updater,CommandHandler,MessageHandler,Filters logging.basicConfig(format = ‘%(asctime)s - %(name)s - %(levelname)s - %(messages)s’,level = logging.INFO) ##asctime = giving at which error occur ##name = name of error ##levelname = there are different level of error it it telling that error ## message = overall meaasge due to exception logger = logging.getLogger(name) #it create logs for program ##CREATE UPDATER #updater is a class of telegram module, it recieves updates from telegram(as it keeps polling the telegram for update) # and send them to dispatcher to be handled Token =“1324234134:AAFVLDl0YQ4_EXvI6rL1QWaaWKFcPHoHFhY” def start(bot,update): #it by default has two args :telegrambot nd update whrr bot is our bot object print(update) author = update.message.from_user.first_name reply = “hi!{}”.format(author) bot.send_message(chat_id = update.message.chat_id, text = reply) def _help(bot,update): help_text = “hey! this is a help text” telegrambot.send_message(chat_id = update.message.chat_id, text = help_text) def echo_text(bot,update): reply = update.message.text bot.send_message(chat_id = update.message.chat_id, text = reply) def echo_sticker(bot,update): bot.send_sticker(chat_id = update.message.chat_id, sticker = update.message.sticker.file_id) def error(bot,update): logger.error(“update ‘%s’ caused error”) def main(): updater = Updater(Token) dp = updater.daipatcher# dp is diapatcher object to handle the updates polled by updater # dispatcher have multiple handler to handle different kind of updates dp.add_handler(CommandHandler(“start”,start)) #if bot recieve /start command start call function dp.add_handler(CommandHandler(“help”,_help)) #if /help command is there then call _help dp.add_handler(MessageHandler(Filters.text,echo_text)) dp.add_handler(MessageHandler(Filters.stickers,echo_sticker)) dp.add_error_handler(error) logger.info(“ustarted polling”) Updater .start_polling() Updater.idle()## it will wait till the user press cntrl+c if name == “main”: main()

please reply …i cant debug this error

can you pls provide the code in an understandable manner I will surely respond you back within 1-2 hours

but if i am pasting my code here it is
getting messed up.can u pls tell another way to provide u my code,so that u can understand my code easily

Use backticks print three backticks ``` paste the code and the again print three backticks

import logging from telegram.ext import Updater,CommandHandler,MessageHandler,Filters logging.basicConfig(format = '%(asctime)s - %(name)s - %(levelname)s - %(messages)s',level = logging.INFO) ##asctime = giving at which error occur ##name = name of error ##levelname = there are different level of error it it telling that error ## message = overall meaasge due to exception logger = logging.getLogger(_name_) #it create logs for program ##CREATE UPDATER #updater is a class of telegram module, it recieves updates from telegram(as it keeps polling the telegram for update) # and send them to dispatcher to be handled Token ="1324234134:AAFVLDl0YQ4_EXvI6rL1QWaaWKFcPHoHFhY" def start(bot,update): #it by default has two args :telegrambot nd update whrr bot is our bot object print(update) author = update.message.from_user.first_name reply = "hi!{}".format(author) bot.send_message(chat_id = update.message.chat_id, text = reply) def _help(bot,update): help_text = "hey! this is a help text" telegrambot.send_message(chat_id = update.message.chat_id, text = help_text) def echo_text(bot,update): reply = update.message.text bot.send_message(chat_id = update.message.chat_id, text = reply) def echo_sticker(bot,update): bot.send_sticker(chat_id = update.message.chat_id, sticker = update.message.sticker.file_id) def error(bot,update): logger.error("update '%s' caused error") def main(): updater = Updater(Token) dp = updater.daipatcher# dp is diapatcher object to handle the updates polled by updater # dispatcher have multiple handler to handle different kind of updates dp.add_handler(CommandHandler("start",start)) #if bot recieve /start command start call function dp.add_handler(CommandHandler("help",_help)) #if /help command is there then call _help dp.add_handler(MessageHandler(Filters.text,echo_text)) dp.add_handler(MessageHandler(Filters.stickers,echo_sticker)) dp.add_error_handler(error) logger.info("ustarted polling") Updater .start_polling() Updater.idle()## it will wait till the user press cntrl+c if _name_ == "_main_": main()

import logging from telegram.ext import Updater,CommandHandler,MessageHandler,Filters logging.basicConfig(format = '%(asctime)s - %(name)s - %(levelname)s - %(messages)s',level = logging.INFO) ##asctime = giving at which error occur ##name = name of error ##levelname = there are different level of error it it telling that error ## message = overall meaasge due to exception logger = logging.getLogger(_name_) #it create logs for program ##CREATE UPDATER #updater is a class of telegram module, it recieves updates from telegram(as it keeps polling the telegram for update) # and send them to dispatcher to be handled Token ="1324234134:AAFVLDl0YQ4_EXvI6rL1QWaaWKFcPHoHFhY" def start(bot,update): #it by default has two args :telegrambot nd update whrr bot is our bot object print(update) author = update.message.from_user.first_name reply = "hi!{}".format(author) bot.send_message(chat_id = update.message.chat_id, text = reply) def _help(bot,update): help_text = "hey! this is a help text" telegrambot.send_message(chat_id = update.message.chat_id, text = help_text) def echo_text(bot,update): reply = update.message.text bot.send_message(chat_id = update.message.chat_id, text = reply) def echo_sticker(bot,update): bot.send_sticker(chat_id = update.message.chat_id, sticker = update.message.sticker.file_id) def error(bot,update): logger.error("update '%s' caused error") def main(): updater = Updater(Token) dp = updater.daipatcher# dp is diapatcher object to handle the updates polled by updater # dispatcher have multiple handler to handle different kind of updates dp.add_handler(CommandHandler("start",start)) #if bot recieve /start command start call function dp.add_handler(CommandHandler("help",_help)) #if /help command is there then call _help dp.add_handler(MessageHandler(Filters.text,echo_text)) dp.add_handler(MessageHandler(Filters.stickers,echo_sticker)) dp.add_error_handler(error) logger.info("ustarted polling") Updater .start_polling() Updater.idle()## it will wait till the user press cntrl+c if _name_ == "_main_": main()

it would be grateful if indentation is correct :sweat_smile: :sweat_smile:

but is it getting wrong when i am pasting my code here.

my code is same as in lecture

just tell me that,does i need to define name passed in getlogger (name)

because i am getting error that name is not defined

In your code the _name_ should contain two double underscores before and after __name__
Make sure to change single underscore to double underscore from everywhere and also “main” too contains double underscores.