title: KeyError when using hex, octal, or binary integer as argument index with Python's str.format() method
body: <p>Simple use of Python's <a href="http://docs.python.org/2/library/stdtypes.html#str.format" rel="nofollow">str.format()</a> method:</p>
  
  <pre><code>&gt;&gt;&gt; '{0}'.format('zero')
  'zero'
  </code></pre>
  
  <p>Hex, octal, and binary literals do not work:</p>
  
  <pre><code>&gt;&gt;&gt; '{0x0}'.format('zero')
  KeyError: '0x0'
  &gt;&gt;&gt; '{0o0}'.format('zero')
  KeyError: '0o0'
  &gt;&gt;&gt; '{0b0}'.format('zero')
  KeyError: '0b0'
  </code></pre>
  
  <p>According to the <a href="http://docs.python.org/2/library/string.html#format-string-syntax" rel="nofollow">replacement field grammar</a>, though, they should:</p>
  
  <blockquote>
  <pre><code>replacement_field ::=  "{" [field_name] ["!" conversion] [":" format_spec] "}"
  field_name        ::=  arg_name ("." attribute_name | "[" element_index "]")*
  arg_name          ::=  [identifier | integer]
  attribute_name    ::=  identifier
  element_index     ::=  integer | index_string
  index_string      ::=  &lt;any source character except "]"&gt; +
  conversion        ::=  "r" | "s"
  format_spec       ::=  &lt;described in the next section&gt;
  </code></pre>
  </blockquote>
  
  <p>The <a href="http://docs.python.org/2/reference/lexical_analysis.html#grammar-token-integer" rel="nofollow">integer grammar</a> is as follows:</p>
  
  <blockquote>
  <pre><code>longinteger    ::=  integer ("l" | "L")
  integer        ::=  decimalinteger | octinteger | hexinteger | bininteger
  decimalinteger ::=  nonzerodigit digit* | "0"
  octinteger     ::=  "0" ("o" | "O") octdigit+ | "0" octdigit+
  hexinteger     ::=  "0" ("x" | "X") hexdigit+
  bininteger     ::=  "0" ("b" | "B") bindigit+
  nonzerodigit   ::=  "1"..."9"
  octdigit       ::=  "0"..."7"
  bindigit       ::=  "0" | "1"
  hexdigit       ::=  digit | "a"..."f" | "A"..."F"
  </code></pre>
  </blockquote>
  
  <p>Have I misunderstood the documentation, or does Python not behave as advertised? (I'm using Python 2.7.)</p>