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)?

有帮助吗?

解决方案

>>> 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>'.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top