0

Follows by the python reference manual we've that

Code objects represent byte-compiled executable Python code, or bytecode.

and

Special read-only attributes: co_name gives the function name;

What is the value of co_name if the current compiled code doesn't depends on any function (i.e. global module code)?

  • 1
    Did you try it? Play around with `compile` function. – BrenBarn Mar 01 '14 at 07:22
  • 2
    `print compile("a = 10", "", "exec").co_name` - `` – thefourtheye Mar 01 '14 at 07:22
  • @BrenBarn I think that we can't take access to an objects of any internal types. Might it possible to recieve an instance of execution frame internal object? –  Mar 01 '14 at 07:26
  • @DmitryFucintv: I don't understand what "take access to an objects of any internal types" means. – BrenBarn Mar 01 '14 at 07:29
  • @BrenBarn Is it possible to get an instance of frame object which correponding to a current execution code block? –  Mar 01 '14 at 07:32

1 Answers1

0
>>> print inspect.currentframe().f_code.co_name
<module>

Using inspect to get the code object of the current stack frame in interactive mode, we find that the co_name is '<module>'.

user2357112
  • 260,549
  • 28
  • 431
  • 505