是否有任何字符串格式化使用正確的後綴與日誌消息,例如:任何漂亮的Python字符串格式爲計數器?
for n in itertools.count():
print 'printing for the {:nth} time'.format(n)
預期輸出:
printing for the 0th time
printing for the 1st time
printing for the 2nd time
printing for the 3rd time
printing for the 4th time
printing for the 5th time
...
printing for the 23rd time
...
printing for the 42nd time
...
etc
我會推出自己很容易,但我想知道是否有已經是一個內置的解決方案。如果沒有,我會接受最優雅的解決方案!
見[這個問題](http://stackoverflow.com/questions/739241/python-date-ordinal-output)。 – DSM 2012-02-20 01:19:47