str.format() doesn't work on python 2.6 #1544

merged 1 commit into from Dec 3, 2012


None yet
3 participants

NelleV commented Nov 29, 2012

Very small fix for something that doesn't work with python2.6:

str.format() has been introduced in python 2.7. There are no tests for this, and it seemed like a lot of trouble to set up a test for this.



pelson commented Nov 29, 2012

The ''.format method was introduced in python26, but interestingly there seems to be a bug in the way it was implemented:

$> python2.6
>>> '{} testing'.format('hello')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: zero length field name in format

>>> '{0} testing'.format('hello')
'hello testing'

In short {} doesn't work, where {0} does (there is a note in the docs that this functionality was added in python2.7). The relevant docs are here:

Having said all of the above, the change you have made is fine too, so lets stick with what you've done. 👍


NelleV commented Nov 29, 2012

Oups, my mistake... Both method are fine with me.

Travis told me the tests don't pass: I don't have any problems on my computer, and I'm not managing to view the bug report.


dmcdougall commented Nov 30, 2012

@NelleV The 'test' failures are actually numpy build failures. Not quite sure what's going on. I posted a message to the mpl-devel list in the hopes of enlightenment.


dmcdougall commented Nov 30, 2012

Also, I think I prefer {0}, but it doesn't really matter at the end of the day.


dmcdougall commented Dec 3, 2012

On python 3.2 % works fine:

>>> a = 'a'
>>> b = 'b'
>>> '%s %s' % (a, b)
'a b'


dmcdougall added a commit that referenced this pull request Dec 3, 2012

Merge pull request #1544 from NelleV/fix_backend
str.format() doesn't work on python 2.6

@dmcdougall dmcdougall merged commit d4fca39 into matplotlib:master Dec 3, 2012

1 check failed

default The Travis build failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment