'Return does not return information
When wanting to return a value with the return and wanting to use it later in a variable, nothing is returned to me.
#Actualizacion de informacion
def messageHandler(update: Update, context: CallbackContext):
userName = update.effective_user['username']
#text = update.message.text
Usuario = userName
ConsultarServer = ("Ingresa tu nombre de troncal correcta de lo contrario no se te regresara ninguna informacion.")
if ConsultarSaldoSw2 in update.message.text:
context.bot.send_message(chat_id=update.effective_chat.id, text="Ingresa tu nombre de troncal correcta de lo contrario no se te regresara ninguna informacion.")
text2 = update.message.text
return text2
print (text2)
if text2 in update.message.text:
context.bot.send_message(chat_id=update.effective_chat.id, text="Ingresa el servidor sw o sw2")
text3 = update.message.text
return text3
print (text3)
Solution 1:[1]
If the function is exhausted, and it doesn't meet any of your conditions, it will return None by default. Consider this shortened example:
def messageHandler(update: Update, context: CallbackContext):
if ConsultarSaldoSw2 in update.message.text:
return text2
if text2 in update.message.text:
return text3
# None of these if conditions are met, so nothing is returned
If you don't enter any of these if statements, you never return a value.
Solution 2:[2]
Return ends the function and does not print anything to the console. Also seems that they're endpoints for conditionals that may not be met.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Naughty Noodler |
