【发布时间】:2019-09-25 13:50:22
【问题描述】:
我正在尝试使用出色的 python-telegram-bot 模块创建一个简单的 Telegram Bot,但我无法将字典与默认的 "{0:<20} {1}".format(key, value) 想法对齐。
让我举个例子:
MAP = {
"one": "1",
"two": "2",
"three": "3",
"four": "4",
"five": "5",
"six": "6",
"seven": "7",
"eight": "8"
}
tmpstring = ""
for key, value in MAP.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 中的消息如下所示:
所以我的问题是: 如何对齐聊天消息,使其看起来像打印输出?
【问题讨论】:
标签: python-3.x telegram-bot python-telegram-bot