格式化Python输出(format Python output)
我正在使用template.format()来对齐两列,就像这样
a 1 b 3 c 6我尝试了以下方法:
template = "{0:30}{2:7}" w.write("| "+(template.format("a",len(a.findall(info)))+"\n")) w.write("| "+template.format("b",count)+"\n")我有这个
a 1 b 5它没有对齐为什么会发生这种情况? 任何人都可以帮助我吗?
I'm using template.format() to have two columns aligned, like this
a 1 b 3 c 6I tried the following:
template = "{0:30}{2:7}" w.write("| "+(template.format("a",len(a.findall(info)))+"\n")) w.write("| "+template.format("b",count)+"\n")I had this
a 1 b 5it is not aligned why did this happen? any one can help me?
最满意答案
我认为你的模板是错误的。 请看看这个:
template = "{:30}{:7}" print(template.format("agasdf","1")) print(template.format("b","ddsfg5ggg")) print(template.format("hgfdhb","5ggg"))在列中提供了很好的格式:
agasdf 1 b ddsfg5ggg hgfdhb 5gggI think your template is wrong. Please have a look at this:
template = "{:30}{:7}" print(template.format("agasdf","1")) print(template.format("b","ddsfg5ggg")) print(template.format("hgfdhb","5ggg"))Gives nice formatting in columns:
agasdf 1 b ddsfg5ggg hgfdhb 5ggg更多推荐
发布评论