[Tutor] bytecode primer, and avoiding a monster download

Dave Angel davea at davea.name
Tue May 28 02:23:49 CEST 2013


On 05/27/2013 07:56 PM, ALAN GAULD wrote:
> I can't speak for Jim, but I have used the dis module in the past to
>> quickly check how python parsed an expression (e.g. not x is y).
>> Yes, I've done that too. But that's not the bytecodes (at least not what
> I understand as bytecodes) that's the dis-assembly listing which is
> usually far more useful. And as you say the dis module provides that
> without any need for other tools.
>


Certainly dis.dis() doesn't show the entire file, it shows only a single 
function.  And it doesn't show the const-table, or the local-table. 
(Whatever they're called in byte-code-speak)

But within the function it's probably got most all of what you would see 
in a byte code file, barring the hex values of the bytes themselves. 
Notice it shows you the offsets, so you know how many bytes each 
instruction takes.  And when the instruction is more than one byte long, 
it shows the operands, in both decimal form and in mnemonic.

When I first got my hands on the (very good) spec for the java byte code 
file, I wrote a disassembler for it.  Seems to me the python one is very 
analogous to that one.

Note, though that I have never tried to even look at the python one, 
even with a hex editor.  So I could be all wet.


-- 
DaveA


More information about the Tutor mailing list