[Tutor] bytecode primer, and avoiding a monster download

Oscar Benjamin oscar.j.benjamin at gmail.com
Tue May 28 19:12:07 CEST 2013


On 28 May 2013 17:48, eryksun <eryksun at gmail.com> wrote:
> On Tue, May 28, 2013 at 7:18 AM, Dave Angel <davea at davea.name> wrote:
>>
>> dis.dis(myfunction)
>>
>> will disassemble one function.
>>
>> That's not all that's in the byte-code file, but this is 98% of what you
>> probably want out of it.  And you can do it in the debugger with just the
>> standard library.
>
> The argument for dis.dis() can be a module, class, function or code
> object. It disassembles all the top-level code objects that it finds,
> but it doesn't recursively disassemble code objects that are in the
> co_consts.

What do you mean by this? I tried passing a test module into dis.dis
and nothing happens:

$ python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tmp
>>> tmp.a
1
>>> import dis
>>> dis.dis(tmp)
>>> print(dis.dis(tmp))
None

This module contains no functions but it does contain lines of code
and the interpreter will turn those into bytecode somewhere. I think
that's what Dave meant.


Oscar


More information about the Tutor mailing list