使用 PyQt4、pyodbc 和 python 3.5.1 我想同时左右对齐结果行。我的意思是:
printing resultrow = "column1:column2"
但我想打印它像
printing resultrow = "column1 : column2"
我正在将结果数据写入 Qt4 应用程序纯文本编辑字段。由于结果正在改变,我不知道需要添加多少空格,所以我需要在纯文本编辑字段上对齐它们,但这只是一种方式,至少据我所知。请建议我解决这个问题。
谢谢...
最佳答案
您可以使用普通的 python 字符串格式进行对齐和空格填充
>>> '{:<15}:{:>15}'.format('column1', 'column2')
'column1 : column2'
如果你想使填充变量
width = len(row)
fmt_str = '{{:<{0}}}:{{:>{0}}}'.format(width)
fmt_str.format('column1', 'column2')
关于python - 如何同时左右对齐结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37412695/