title: Reading in integer from stdin in Python
body: <p>I have the following piece of code where I take in an integer n from stdin, convert it to binary, reverse the binary string, then convert back to integer and output it.</p>
  
  <pre><code>import sys
  
  def reversebinary():
    n = str(raw_input())
    bin_n = bin(n)[2:]
    revbin = "".join(list(reversed(bin_n)))
    return int(str(revbin),2)
  
  reversebinary()
  </code></pre>
  
  <p>However, I'm getting this error:</p>
  
  <pre><code>Traceback (most recent call last):   
  File "reversebinary.py", line 18, in &lt;module&gt;
    reversebinary()   
  File "reversebinary.py", line 14, in reversebinary
     bin_n = bin(n)[2:] 
  TypeError: 'str' object cannot be interpreted as an index
  </code></pre>
  
  <p>I'm unsure what the problem is.</p>