如何格式化 bot 'send_message' 输出使其像 table 一样对齐?

How to format bot 'send_message' output so it aligns like a table?

我正在尝试使用 python-telegram-bot 库创建一个简单的 Telegram Bot,但我无法将字典与默认的 "{0:<20} {1}".format(key, value) 想法对齐。

让我举个例子:

Mapy = {
    "one": "1",
    "two": "2",
    "three": "3",
    "four": "4",
    "five": "5",
    "six": "6",
    "seven": "7",
    "eight": "8"
}

tmpstring = ""

for key, value in Mapy.items():
    tmpstring = tmpstring + "{0:<20} {1}".format(key, value) + "\n"

print(tmpstring)
context.bot.send_message(chat_id=update.message.chat_id, text=tmpstring)

印刷完成看起来像这样:

one                  1
two                  2
three                3
four                 4
five                 5
six                  6
seven                7
eight                8

正如预期的那样很好地对齐,但 Telegram 中的消息看起来像这样:

所以我的问题是: 我怎样才能对齐聊天消息,使其看起来像打印输出?

使用Markdowns (V2) 'pre-formatted fixed-width code block' to preserve the alignment. [Docs]

使用 3[= 将 完美对齐 table 包裹在 code-block 中25=] back-ticks (```)

```
one          1
two          2
three        3
```

使用 parse_mode option set to: MarkDown (V2)

发送您的消息