【发布时间】:2020-01-09 11:28:06
【问题描述】:
我正在尝试打印一个字符串。
目前打印如下:print("\t" + errorstr)
HTTPConnectionPool(host='localhost', port=10248): Max retries exceeded with url: /healthz
(Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9a92d5e6d0>:
Failed to establish a new connection: [Errno 111] Connection refused',))
仅在第一行添加选项卡。
然后我尝试了:
print("\t"+u"{: ^32s}".format(errorstr))
但它仍然提供相同的输出。
我希望它是这样的:
HTTPConnectionPool(host='localhost', port=10248): Max retries exceeded with url: /healthz
(Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at
0x7f9a92d5e6d0>:
Failed to establish a new connection: [Errno 111] Connection refused',))
每一行都应包含tab 空格。我如何在python 中做到这一点?
PS:我使用 python 2.7 是有原因的,所以我无法更改版本,我想使用默认的 python 包来执行此操作,而不是任何第三方库
【问题讨论】:
-
这能回答你的问题吗? Printing with indentation in python
标签: python