0
我想執行填充和限制一個變量的小數點數,這些變量將使用.format輸入到一個字符串中。我設法限制小數位數,但我似乎無法添加填充。 documentation沒有太大的幫助。以下是我的代碼的副本。Python:爲相同變量多次格式佔位符
print "Frame No. {:6d} Expected: {:7.3f}ms Actual: {:7.3f}ms Difference: {:7.3f}ms - ERROR".format(currentImage, expected_time, regression_obj.timeFromStart, (regression_obj.timeFromStart - expected_time))
此處的輸出顯示值之間沒有足夠的空格。我希望所有的值都一致。
Frame No. 17 Expected: 582.080ms Actual: 484.971ms Difference: -97.109ms - ERROR
Frame No. 18 Expected: 616.320ms Actual: 513.498ms Difference: -102.822ms - ERROR
預期產量;
Frame No. 17 Expected: 582.080ms Actual: 484.971ms Difference: -97.109ms - ERROR
Frame No. 18 Expected: 616.320ms Actual: 513.498ms Difference: -102.822ms - ERROR
所以問題是,有沒有足夠的空間值之間的寬度是多少? – wnnmaw
您的預期產出是多少? – tayfun
@wnnmaw是的,請參閱問題 – Marmstrong