florentx/stringformat — pull request #1 by igg (2012-05-10 05:37:26+00:00)
Title: monkey patch fancy string formatting for string literals in older pythons

The motivation for this was that we wanted to use fancy string formatting in our code without requiring our users to upgrade to 2.7.

Your module lets us do exactly what we want, except that to a great extent, format() is called on string literals instead of using a class/instance syntax. The consensus seems to be that monkey patching builtins is a nasty business, and certainly modifying the behavior of literals is impossible. Recently though I found some code on gist that does just that (), written by Armin R. (presumably Armin Ronacher). So I combined the two things, allowing for fancy string formatting on literals in pythons down to 2.4.

The monkey patch is applied to str and unicode on import in pythons >=2.4 and < 2.7. Tested so far on pythons 2.5.6, 2.6.7, 2.7.1. I added tests for str and unicode literals in selftest(), but not in tests.py

```python
import stringformat
print "{0:{width}.{precision}s}".format('hello world',width=8, precision=5)
```