Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

3 participants

@NelleV
Collaborator

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.

Cheers,
N

@pelson
Collaborator

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: http://docs.python.org/2/library/string.html#format-string-syntax.

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

@NelleV
Collaborator

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
Collaborator

@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
Collaborator

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

@dmcdougall
Collaborator

On python 3.2 % works fine:

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

Merging...

@dmcdougall dmcdougall merged commit d4fca39 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 29, 2012
  1. @NelleV
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 4 deletions.
  1. +3 −4 lib/matplotlib/backends/backend_gtk.py
View
7 lib/matplotlib/backends/backend_gtk.py
@@ -326,7 +326,7 @@ def leave_notify_event(self, widget, event):
def enter_notify_event(self, widget, event):
x, y, state = event.window.get_pointer()
- FigureCanvasBase.enter_notify_event(self, event, xy=(x,y))
+ FigureCanvasBase.enter_notify_event(self, event, xy=(x, y))
def _get_key(self, event):
if event.keyval in self.keyvald:
@@ -339,9 +339,9 @@ def _get_key(self, event):
for key_mask, prefix in (
[gdk.MOD4_MASK, 'super'],
[gdk.MOD1_MASK, 'alt'],
- [gdk.CONTROL_MASK, 'ctrl'],):
+ [gdk.CONTROL_MASK, 'ctrl'], ):
if event.state & key_mask:
- key = '{}+{}'.format(prefix, key)
+ key = '%s+%s' % (prefix, key)
return key
@@ -360,7 +360,6 @@ def configure_event(self, widget, event):
return False # finish event propagation?
-
def draw(self):
# Note: FigureCanvasBase.draw() is inconveniently named as it clashes
# with the deprecated gtk.Widget.draw()
Something went wrong with that request. Please try again.