(Sep-28-2023, 06:59 AM)akbarza Wrote: ? what does co_names
do? where can I get more info about it?
It's an attribute(method) of built-in compile().So if want look more at it has to look tutorials about
compile()
,and not
.co_names
alone which is just one method. >>> code = compile('print(55)', 'test', 'eval') >>> exec(code) 55 # Use a couple of methods >>> code.co_names ('print',) >>> code.co_code b'\x97\x00\x02\x00e\x00d\x00\xa6\x01\x00\x00\xab\x01\x00\x00\x00\x00\x00\x00\x00\x00S\x00' # All >>> [i for i in dir(code) if not i.startswith('__')] ['_co_code_adaptive', '_varname_from_oparg', 'co_argcount', 'co_cellvars', 'co_code', 'co_consts', 'co_exceptiontable', 'co_filename', 'co_firstlineno', 'co_flags', 'co_freevars', 'co_kwonlyargcount', 'co_lines', 'co_linetable', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals', 'co_positions', 'co_posonlyargcount', 'co_qualname', 'co_stacksize', 'co_varnames', 'replace'] # look at help for compile >>> help(compile) Help on built-in function compile in module builtins: compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1, *, _feature_version=-1) Compile source into a code object that can be executed by exec() or eval(). The source code may represent a Python module, statement or expression. The filename will be used for run-time error messages. The mode must be 'exec' to compile a module, 'single' to compile a single (interactive) statement, or 'eval' to compile an expression. The flags argument, if present, controls which future statements influence the compilation of the code. The dont_inherit argument, if true, stops the compilation inheriting the effects of any future statements in effect in the code calling compile; if absent or false these statements do influence the compilation, in addition to any features explicitly specified.