dis.dis question

Ron Adam rrr at ronadam.com
Sun Oct 16 05:40:57 EDT 2005


skip at pobox.com wrote:

>     >> I'm still looking for info on how to use disassemble_string().
> 
> How about this?
> 
>     >>> import dis
>     >>> def f():
>     ...   print "hello world"
>     ... 
>     >>> f.func_code.co_code
>     'd\x01\x00GHd\x00\x00S'
>     >>> dis.disassemble_string(f.func_code.co_code)
>               0 LOAD_CONST          1 (1)
>               3 PRINT_ITEM     
>               4 PRINT_NEWLINE  
>               5 LOAD_CONST          0 (0)
>               8 RETURN_VALUE   
> 
> Skip

Thanks Skip,  I had figured it out, but I like your example.

 >>> import dis
 >>> dis.dis('d\x01\x00GHd\x00\x00S')
               0 LOAD_CONST               1 (1)
               3 PRINT_ITEM
               4 PRINT_NEWLINE
               5 LOAD_CONST               0 (0)
               8 RETURN_VALUE

It works!  :-)

Cheers,
    Ron







More information about the Python-list mailing list