Say I am in the python interpreter and define a function as follows:
def h(a):
return a
If I want to look at the bytecode (not a disassembly using dis), I can typically use h.func_code.co_code. Is there any other way to look at the bytecode?
For example, in the interpreter, if I just type h without making it a function call, I get the address of the function. Can I use that address to get the bytecode? Is there some other way?
Some additional info from the comments:
The app is written in python and packed using something like Py2App, cx_freeze, or py2exe. I played some tricks on the executable and now, when launched, the executable dumps me to a python command line. From there, I manually typed my function h into the interepeter.
Other attributes of h.func_code are present such as co_varnames, co_argcount, etc, but co_code is not.
If I type in h.func_code.co_code into the interpreter, I get 'code' object has no attribute 'co_code'.
UPDATE: From the comments again. As far as I can tell the opcodes have been remapped for the python interpreter that was shipped with the app.
If you have defined your own
def h(): passdummy function, and that function does not have a.func_code.co_codevalue, then most likely the included python interpreter is a custom compiled version where theco_codeslot has been cleared.The work-around is simple, copy the
Contents/Resourceszipfiles (in all subdirs) elsewhere, add those to yourPYTHONPATHand import the code into your own interpreter.