【问题标题】:Python conflict with keyword "from" in telegram botPython与电报机器人中的关键字“from”冲突
【发布时间】:2016-10-29 15:08:03
【问题描述】:

我想使用 python-telegram-bot 在 Python 脚本中打印用户信息,参考 this 页面

但是当我输入时

print update.message.from

关键字.from 被识别为内部保留关键字,我收到无效语法错误。

我该如何解决?

谢谢。

【问题讨论】:

  • 我假设 API 返回 json?因此,您应该能够加载响应,然后访问其属性,例如 update['message']['from'] 或类似的东西。
  • 虽然您不能直接在源代码中指定无效的名称属性,但您可以这样做:getattr(update.message, 'from')

标签: python telegram-bot python-telegram-bot


【解决方案1】:

正如python-telegram-bot code 本身所解释的那样:

  • 在 Python 中,from 是保留字,请改用from_user

所以:print update.message.from_user

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-18
    • 2018-02-27
    • 2020-10-28
    • 1970-01-01
    • 2018-03-23
    • 2020-08-20
    • 2022-01-01
    • 2021-02-21
    相关资源
    最近更新 更多