In python 2.6, a new standard string method was introduced: format(). I have started using it a lot in my python code and it is the new standard way to format strings in python 3.0.
I also write a lot of javascript, and probably more javascript than python, but debugging in javascript is difficult and I’ve overridden firebug’s console.log() and console.dir() for my conveniences. In order to make those conveniences even easier, I’ve added a format method that implements the simple replacement fields portion of python’s format().
Here it is:
It’s not perfect and it’s far from python’s full implementation, but it works 98% of the time I want to use something like this.
thirstymind.org is
the personal site of Andrew Watts, where I share my thoughts on software, technology & life.