Rad*_*Hex 3 python string string-formatting
这是我正在尝试做的一个简单的例子
box = {
'colour': 'Red',
'dimensions': {
'width': '100px',
'height': '333px',
}
}
print "The box is %(colour)s, wide %(dimensions.width) and high %(dimensions.height)" %box
Run Code Online (Sandbox Code Playgroud)
这可能与标准库有关吗?
如果没有,你会推荐哪些图书馆?
sbe*_*rry 10
>>> box = {
'colour': 'Red',
'dimensions': {
'width': '100px',
'height': '333px',
}
}
>>> print "The box is {colour}, wide {dimensions[width]} and high {dimensions[height]}".format(**box)
The box is Red, wide 100px and high 333px
Run Code Online (Sandbox Code Playgroud)