Python 对齐和非默认浮点表示法

Python 对齐和非默认浮点表示法,python,string,format,Python,String,Format,在我的工作中,我经常在开始使用之前检查一些文件的内容,然后我开始用这些检查和一些漂亮的打印来创建ipython笔记本,以总结我得到的东西。为此,我通常使用print和str.format获取有序输出或浮点数小数。我能做的总结如下: f = 32.4321413432 a = 34121 print('float {ff} and integer {ii}'.format(ff=f, i=i)) print('float {ff:.4f} and integer {ii:d}'.format(ff

在我的工作中,我经常在开始使用之前检查一些文件的内容,然后我开始用这些检查和一些漂亮的打印来创建ipython笔记本,以总结我得到的东西。为此,我通常使用
print
str.format
获取有序输出或浮点数小数。我能做的总结如下:

f = 32.4321413432
a = 34121
print('float {ff} and integer {ii}'.format(ff=f, i=i))
print('float {ff:.4f} and integer {ii:d}'.format(ff=f, ii=i))
print('float {ff:>20} and integer {ii:>10}'.format(ff=f, ii=i))
输出

float 32.4321413432 and integer 34121
float 32.4321 and integer 34121
float        32.4321413432 and integer      34121
有时我希望能够将对齐方式和小数位数设置在一起,并得到这样的输出

float        32.4321 and integer      34121
我在
{ff:…}
中尝试了许多
.4f
.20
的组合,但我得到了

ValueError:转换规范无效

我想要的可能吗?如果可能,语法是什么?

你的意思是这样的吗

f = 32.4321413432
i = 34121
print('float {ff:>20.4f} and integer {ii:>10}'.format(ff=f, ii=i))
产生

float              32.4321 and integer      34121
你是说像这样吗

f = 32.4321413432
i = 34121
print('float {ff:>20.4f} and integer {ii:>10}'.format(ff=f, ii=i))
产生

float              32.4321 and integer      34121