title: Determining magic number without imp.get_magic( )
body: <p>I'm trying to troubleshoot an interesting issue from a user that involves bytecode.  I wanted to determine the magic number associated with these files, to see if they were compiled with different versions.  Unfortunately, we're using Jython, which does not appear to have <code>imp.get_magic()</code>.  Does anyone know of an alternate way to determine the magic number?  I started looking at the files in a text editor to examine the "first word" as <a href="https://stackoverflow.com/a/514395/426649">this answer</a> does.  But I don't know where, among the slashes and numbers, the "first word" ends.  Does anyone know how to figure this out by looking at the actual bytecode?  Or does anyone know how Jython's handling of bytecode differs from Python's?  I was under the impression that it was done the same way (except for writing *$py.class files instead of *.pyc files), but now I'm not so sure.</p>
  
  <p>EDIT:
  First, I decided that trying to read the binary files in a text editor was just silly.  I created a module and compiled it to a <code>*.pyc</code> with Python, then determined the magic number with</p>
  
  <pre><code>with open('compiledModule.pyc', 'rb') as binaryFile:
      magicNumber = binaryFile.read(4)
  print magicNumber.encode('hex')
  </code></pre>
  
  <p>which matched the magic number (as it should) from the version of Python that created it, as reported by:</p>
  
  <pre><code>print imp.get_magic().encode('hex')
  </code></pre>
  
  <p>When I compiled the same module with Jython, into a '*$py.class' file, and read it in with</p>
  
  <pre><code>with open('compiledModule$py.class', 'rb') as otherFile:
      cafeBabe = otherFile.read(4)
  print cafeBabe.encode('hex')
  </code></pre>
  
  <p>it indeed came back as <code>cafebabe</code>.  So in this case, where I was trying to determine the version of Jython that created the bytecode, it appears that I cannot.</p>