質問

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