title: Unpacking bytes to int
body: <p>I'm new to struct module and I'm trying to do something like this:</p>
  
  <pre><code>value = myClient.mySocket.recv(4)
  struct.unpack("I",value)
  </code></pre>
  
  <p>Getting value from my server and then unpack it to integer, I'm receving the value but it won't unpack giving me this error:</p>
  
  <pre><code>struct.error: unpack requires a bytes object of length 4
  </code></pre>
  
  <p>EDIT:
  Ok, so as Martijn Pieters told me there is nothing stored in <code>value</code> whne exception is thrown, but there is another part of my code</p>
  
  <pre><code>value = myClient.mySocket.recv(4)
  struct.unpack("I",value)
  if value == 2:
     #do smth
  </code></pre>
  
  <p>And I saw in the debugger that <code>value</code> recieved <code>b'\x02\x00\x00\x00'</code> but the unpack doesn't change it to <code>int</code> so the if statement doesn't execute and in another loop iteration server sends nothing and there is exception. How to unpack this byte value to integer?</p>
  
  <p>EDIT2: Ok I solved it</p>
  
  <pre><code>value = myClient.mySocket.recv(4)
  value = struct.unpack("I",value)
  if value[0] == 2:
    #do smth
  </code></pre>