Search code examples
pythontelegram-botpython-telegram-bot

Python conflict with keyword "from" in telegram bot


I would like to print user information in Python script using python-telegram-bot referring to this page

But when I type

print update.message.from

keyword .from is recognized as internal reserved keyword and I get invalid syntax error.

How can I solve?

Thanks.


Solution

  • As explained in the python-telegram-bot code and documentation itself:

    • In Python from is a reserved word, use from_user instead.

    So: print update.message.from_user.